powmedia / backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
MIT License
2.17k stars 413 forks source link

form loses reference after update DOM #400

Closed hnqso closed 10 years ago

hnqso commented 10 years ago

I have the follow case where I need update dynamically the form DOM after the form has been rendered and added to the DOM e.g.

form = new Backbone.Form({
  template: _.template($('formTemplate').html()),
  model: user,
}).render();

$('#signupForm').html(
  form.el
);

// update form dom
$('#signupForm')
  .prepend('<input type="hidden" name="meta" value="off">');

// doesn't work
form.on('submit', function(e){
  // ...
})

However the form submit stop working and things like validation doesn't work as well, the form is submit directly. Any workaround for this?

Thanks

powmedia commented 10 years ago

You'll need to add the 'meta' field as a new field within the Backbone.Form schema rather than adding it simply as HTML. Then re-render the form.

On Mon, Jul 14, 2014 at 4:08 PM, Henrique Alves notifications@github.com wrote:

I have the follow case where I need update dynamically the form DOM after the form has been rendered and added to the DOM e.g.

form = new Backbone.Form({ template: _.template($('formTemplate').html()), model: user,}).render(); $('#signupForm').html( form.el); // update form dom$('#signupForm') .prepend(''); // doesn't workform.on('submit', function(e){ // ...})

However the form submit stop working and things like validation doesn't work as well, the form is submit directly. Any workaround for this?

Thanks

Reply to this email directly or view it on GitHub https://github.com/powmedia/backbone-forms/issues/400.

hnqso commented 10 years ago

@powmedia my problem is more complex than that because I'm working with localisation and the locales are in the schema. I'm going to do a different approach so I don't have to re-render the form. I'm closing this issues. Keep the good work mate!