powmedia / backbone-forms

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

Form#setSchema helper method to allow dynamic updating of schema #274

Open philfreo opened 11 years ago

philfreo commented 11 years ago

I've needed to dynamically change a form schema and then re-render the form.

Right now you can say:

form.schema = newSchema

but then form.fieldsets, form.selectedFields, etc. get out-of-date and have to also be re-set manually.

I'd propose adding a setSchema helper method to Form to make this nicer.

wyuenho commented 11 years ago

I'd really prefer it if I could insert or remove fields with methods, which essentially calls createField internally and append or remove from the container. Rerendering is a no go on mobile. I don't thinks people would want the screen to be jumping around, losing focus to field but the keyboard is still hanging around etc as soon as I've picked a value from a select box.

The way I do it currently is to override the Form#render method and #initialize to listen to couple of key change events, the resulting code is quite nasty.

philfreo commented 11 years ago

Let's move discussion about this use case back to #273.

I opened this issue for other use cases where you plan on re-rendering the form anyway (when it's not currently visible) but want to update the schema first.

philfreo commented 11 years ago

Current workaround in the case where you want to take an existing form instance, tweak the schema, and re-display it:

form.schema = _.result(this.model, 'schema'); // or whatever
form.initialize();
form.render();

I'm not sure if calling initialize a 2nd time is OK. If so, this ticket can probably be closed. If not, then we should have a helper method that sets this.fields, this.fieldsets, etc. automatically.

carofragueiro commented 10 years ago

Hi! Has anyone found an answer to this problem ?

vip32 commented 10 years ago

form.initialize(); works fine