fix issue #388
This commit is contained in:
parent
04d9fe17f8
commit
d3e219018b
@ -50,11 +50,13 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
|
|||||||
settings = _.extend {}, @tinyMCE_settings(),
|
settings = _.extend {}, @tinyMCE_settings(),
|
||||||
oninit: ((editor) =>
|
oninit: ((editor) =>
|
||||||
$.cmd 'S', (() =>
|
$.cmd 'S', (() =>
|
||||||
$(textarea).val(editor.getBody().innerHTML).trigger('change')
|
editor.save()
|
||||||
|
$(textarea).trigger('changeSilently')
|
||||||
@$('form').trigger('submit')
|
@$('form').trigger('submit')
|
||||||
), [], ignoreCase: true, document: editor.dom.doc),
|
), [], ignoreCase: true, document: editor.dom.doc),
|
||||||
onchange_callback: (editor) =>
|
onchange_callback: (editor) =>
|
||||||
$(textarea).val(editor.getBody().innerHTML).trigger('change')
|
editor.save()
|
||||||
|
$(textarea).trigger('changeSilently')
|
||||||
|
|
||||||
$(textarea).tinymce(settings)
|
$(textarea).tinymce(settings)
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ class Locomotive.Views.Shared.FormView extends Backbone.View
|
|||||||
previous_attributes = _.clone @model.attributes
|
previous_attributes = _.clone @model.attributes
|
||||||
|
|
||||||
@model.save {},
|
@model.save {},
|
||||||
headers: options.headers
|
headers: options.headers
|
||||||
|
silent: true # since we pass an empty hash above, no need to trigger the callbacks
|
||||||
success: (model, response, xhr) =>
|
success: (model, response, xhr) =>
|
||||||
form.trigger('ajax:complete')
|
form.trigger('ajax:complete')
|
||||||
|
|
||||||
|
@ -64,10 +64,13 @@ Backbone.ModelBinding = (function(Backbone, _, $){
|
|||||||
this.modelBindings.push({model: model, eventName: eventName, callback: callback});
|
this.modelBindings.push({model: model, eventName: eventName, callback: callback});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.registerElementBinding = function(element, callback){
|
this.registerElementBinding = function(element, callback, callbackSilently){
|
||||||
// bind the form changes to the model
|
// bind the form changes to the model
|
||||||
element.bind("change", callback);
|
element.bind("change", callback);
|
||||||
this.elementBindings.push({element: element, eventName: "change", callback: callback});
|
this.elementBindings.push({element: element, eventName: "change", callback: callback});
|
||||||
|
|
||||||
|
if (callbackSilently)
|
||||||
|
element.bind("changeSilently", callbackSilently)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,18 +191,24 @@ Backbone.ModelBinding = (function(Backbone, _, $){
|
|||||||
element.val(val);
|
element.val(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
var setModelValue = function(attr_name, value){
|
var setModelValue = function(attr_name, value, silent){
|
||||||
|
if (typeof(silent) === 'undefined' || silent == null) silent = false
|
||||||
var data = {};
|
var data = {};
|
||||||
data[attr_name] = value;
|
data[attr_name] = value;
|
||||||
model.set(data);
|
model.set(data, { 'silent': silent });
|
||||||
};
|
};
|
||||||
|
|
||||||
var elementChange = function(ev){
|
var elementChange = function(ev){
|
||||||
setModelValue(attribute_name, view.$(ev.target).val());
|
setModelValue(attribute_name, view.$(ev.target).val());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FIXME (Did): simple solution to update the model without triggering related callbacks (solving a bug with tinymce)
|
||||||
|
var elementChangeSilently = function(ev) {
|
||||||
|
setModelValue(attribute_name, view.$(ev.target).val(), true);
|
||||||
|
}
|
||||||
|
|
||||||
modelBinder.registerModelBinding(model, attribute_name, modelChange);
|
modelBinder.registerModelBinding(model, attribute_name, modelChange);
|
||||||
modelBinder.registerElementBinding(element, elementChange);
|
modelBinder.registerElementBinding(element, elementChange, elementChangeSilently);
|
||||||
|
|
||||||
// set the default value on the form, from the model
|
// set the default value on the form, from the model
|
||||||
var attr_value = model.get(attribute_name);
|
var attr_value = model.get(attribute_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user