Form generator that uses different models

42 views
Skip to first unread message

minis...@gmail.com

unread,
Feb 12, 2016, 11:19:17 AM2/12/16
to Backbone-forms
Hi,

I'm trying out Backbone.Form and like it so far.

I'd like to be able to have some class/function that AJAX updates a form but that isn't tied to a specific model.

No problem generating the actual inputs obviously, however I have an issue with setting the '.on' events and wondered if anyone had succeeded.

I'm trying this:

        $.each( Object.keys(model.schema), function() {
            key = this;
            event = 'change:' + this;
            form.model.on(
                event, function(model, name) {
                    form.setValue({ this: name });
                }, this);
        });

But the inputs don't get updated when the AJAX returns, whereas this works:

        form.model.on({
            'change:field1': function(model, name) {
                form.setValue({ field1: name });
            },
            'change:field2': function(model, name) {
                form.setValue({ field2: name });
            },
            'change:field3': function(model, name) {
                form.setValue({ field3: name });
            }
        });

Can anyone help?

Thanks

Mini

minis...@gmail.com

unread,
Feb 13, 2016, 9:32:53 AM2/13/16
to Backbone-forms
Oops - sorted it by doing changing Object.keys to Object.getOwnPropertyNames and changing the call to form.setValue (in case anyone else reads this):

        Object.getOwnPropertyNames(species.schema).forEach( function( key ) {
            var event = 'change:' + key;
            form.model.on(
                event,
                function(model, name) {
                    form.setValue( key, name );
                }
            );
        });
Reply all
Reply to author
Forward
0 new messages