Venkatesh Bachu
Venkatesh Bachu

Reputation: 2553

reset fieldset values in backbone.js

I am having a fieldset in jQuery template:

<script id="tmpl_companies" type="x-jquery-tmpl">
    <fieldset id="add-row" class="clearfix">
        <div>
            <label for="industry_type">Industry Type: </label>
            <input type="text" id="industry_type" value="${industry_type}"><br/>
        </div>
        <div>
            <label for="hiring_company_name">Hiring_Company Name: </label>
            <input type="text" id="company_name" value=${hiring_company_name}><br/>
        </div>
        <div class="last">
            <button type="submit" id="save" name="save" alt="save" >
                <img src="/assets/img/add.png" />
            </button>
            <button type="reset" id="reset" name="reset" alt="reset" >
                <img src="/assets/img/cancel.png" />
            </button>
        </div>
    </fieldset>
</script>

How can I reset the fieldset values by clicking the reset button

'click #reset' : 'reset'

in backbone.js

reset: function() {
  ???????
}

Upvotes: 0

Views: 3222

Answers (2)

Venkatesh Bachu
Venkatesh Bachu

Reputation: 2553

<script id="tmpl_companies" type="x-jquery-tmpl">

<fieldset id="add-row" class="clearfix">
<form>  // missed here

<div><label for="industry_type">Industry Type: </label>
<input type="text" id="industry_type" value="${industry_type}"><br/>
</div>
<div><label for="hiring_company_name">Hiring_Company Name: </label>
<input type="text" id="company_name" value=${hiring_company_name}><br/>
</div>
<div class="last">
<button type="submit" id="save" name="save" alt="save" ><img src="/assets/img/add.png"    /></button>
<button type="reset" id="reset" name="reset" alt="reset" ><img src="/assets/img/cancel.png" /></button>

</div>
</form>  //missed here
</fieldset>
</script>

Upvotes: 0

Derick Bailey
Derick Bailey

Reputation: 72868

Don't handle this in backbone. Just let the browser reset the form for you, using the <input type="reset"> button.

If you must use Backbone, just re-render the view:


  reset: function(){
    this.render();
  },

  render: function(){
    var html = $("#my-template").tmpl(this.model.toJSON());
    this.$el.html(html);
  }

Upvotes: 3

Related Questions