Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to enable/disable save button of backbone form-view when user changes form content
    primarykey
    data
    text
    <p>I have form which gets data from backbone model. When the form is shown, they have initially value set to backbone model. Now, if any field is edited, i want to enable "save" button immediately as soon as any changes is made to field. However, if you change field value and again change it to original, it should again disable the "save" button that allows to save model.I want to achieve as one shown in this jsfiddle :<a href="http://jsfiddle.net/qaf4M/2/" rel="nofollow">http://jsfiddle.net/qaf4M/2/</a></p> <p>I am using backbone.js and backbone.stick (<a href="http://nytimes.github.io/backbone.stickit/" rel="nofollow">http://nytimes.github.io/backbone.stickit/</a>) to bind model to template.</p> <p>I create view as follows with model as parameter</p> <pre><code>RegionManager.show(new app.myView({ model : new app.myModel( {id: 1}) })); </code></pre> <p>MY model value is something like this:</p> <pre><code> { "id":1, "name:"a" , "age":21 } </code></pre> <p>The view is as follows:</p> <pre><code>myView = Backbone.View.extend({ template: _.template( $("#template").html() ), events: { "click #save" : "update", }, bindings: { '#id': 'id', '#name': 'name', '#age': 'age' }, initialize: function () { if(this.model){ this.model.fetch(); }, render: function () { this.$el.html( this.template ); this.stickit(); //used library http://nytimes.github.io/backbone.stickit/ Backbone.Validation.bind(this); }, update: function() { this.model.save ( {success: this.success_callback, error: this.error_callback}); }, success_callback: function (model, response) { }, error_callback: function (model, response) { alert('error.'); } }); </code></pre> <p>My template look like </p> <pre><code> &lt;script type="text/template" id="template"&gt; &lt;form id="myForm " &gt; &lt;fieldset&gt; &lt;label&gt;Name&lt;/label&gt; &lt;input type="text" id="name" name="name" /&gt; &lt;label&gt;Age&lt;/label&gt; &lt;input type="text" id="age" name="age" /&gt; &lt;input type="hidden" id="id" name="id"/&gt; &lt;/fieldset&gt; &lt;a id="save" disabled &gt;Save Changes&lt;/a&gt; &lt;/form&gt; </code></pre> <p>I am confused where should i bind event and how or what is proper way to know the user has chagne some value and accordingly disable button when there is no cahnge in form and enable when change has been made.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload