Reputation: 671
I'm getting a weird JS TypeError:
TypeError: $(...).formset is not a function
added: function(row) {
Now, the JS looks like this:
$('#richtextcontent_set-group .inline-related').formset({
prefix: "richtextcontent_set",
addText: "Text hinzufügen",
formCssClass: "dynamic-richtextcontent_set",
deleteCssClass: "inline-deletelink",
deleteText: "Entfernen",
emptyCssClass: "empty-form",
removed: updateInlineLabel,
added: function(row) {
initPrepopulatedFields(row);
reinitDateTimeShortCuts();
updateSelectFilter();
updateInlineLabel(row);
}
});
It really can't be the .formset()
call. If I execute
$('#richtextcontent_set-group .inline-related').formset({})
in the console, it doesn't return any errors.
And the added:
option obviously receives a function.
I'm using the django-dynamic-formset plugin: http://code.google.com/p/django-dynamic-formset/
So what could be the problem here?
I will happily provide more information if necessary. Thanks.
UPDATE
The django inlines.js (containing formset()
) really wasn't loaded due to a messy monkeypatch on the InlineModelAdmin that was overriding it's media property. Thanks for the comments and answer.
Upvotes: 1
Views: 911
Reputation: 17361
Try to log the output just before the offending code.
var formset = $('#richtextcontent_set-group .inline-related').formset;
// have a look at formset
console.log(formset);
formset({
...
configuration properties
...
});
If undefined
is returned to the console the plugin is not loaded at the time you're calling it. In that case it's best to execute your code when the dom is ready. This example wraps it inside $(function() { ... })
to do exactly that.
$(function () {
$('#richtextcontent_set-group .inline-related').formset({
...
configuration properties
...
}));
});
Now you're almost certain it's executed when to plugin is loaded.
Upvotes: 2