I have very complex forms in my application with update functionality where user may change only few fields click on save button to submit data to server. My application uses backbone, syphon, JQuery and underscoreJs.
What is the best way to control what fields can be sent to server using only with these libraries which can be used across several pages within my application? Something like reusable functionality will be helpful.
I have tried model.changedAttributes()
function which doesn't seem to be working as expected. Most of the times, it is returning false. I have the following code where form data gets serialized using syphon then will be converted into my app specific format to send to API.
formSave: function(e) {
var data = changeToWriteApiFormat(Backbone.Syphon.serialize($(e.currentTarget).closest('form.event_form')[0]));
this.model.clear();
this.model.id = this.parentObj.model.id;
this.model.set(data);
if (this.model.isValid(true)) {
this.model.save(removeObjIndexCollection(data), {
url: this.model.url().replace(gc.readApiUrl, gc.publishApiUrl),
patch: true,
beforeSend: ToolsHelper.setPublishHeader,
success: function(model, response) {
$('#event_success').show();
$('#event_failure').hide();
},
error: function(model, response) {
$('#event_failure').show();
$('#event_success').hide();
}
}
}