mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 20:16:39 -04:00
23 lines
No EOL
718 B
JavaScript
23 lines
No EOL
718 B
JavaScript
var ModelForm = Class.extend({
|
|
|
|
generateFor: function (model, formSelector) {
|
|
this.model = model;
|
|
this.formOptions = model.formOptions;
|
|
|
|
$(formSelector).jsonForm({ schema: this.model.formSchema() });
|
|
},
|
|
|
|
submit: function (createHandler, updateHandler) {
|
|
this.updateModelFromFormValues()
|
|
this.model.save(createHandler, updateHandler)
|
|
},
|
|
|
|
updateModelFromFormValues: function() {
|
|
for (field in this.model.schema) {
|
|
var regexExpression = ':regex(id, jsonform.*' + field + ')';
|
|
var htmlElement = $(regexExpression);
|
|
if (this.model.schema[field].constructor == Boolean) this.model.schema[field] = !!htmlElement.attr('checked');
|
|
else this.model.schema[field] = htmlElement.val();
|
|
}
|
|
}
|
|
}); |