backbone-forms icon indicating copy to clipboard operation
backbone-forms copied to clipboard

List editor not sending events

Open exussum12 opened this issue 11 years ago • 10 comments

From the docs

 Events fired by any item's editor will bubble up and be fired as item:<event>.

But no events seem to be fired for the list editor, I would expect item:change or listName:item:change to be fired when something inside the modal editor is changed.

It works ok for list type text, but not for list type nested model

exussum12 avatar Feb 05 '14 11:02 exussum12

https://github.com/powmedia/backbone-forms/blob/master/distribution/adapters/backbone.bootstrap-modal.js#L58

Is probably where it should be added for the adapater and then

https://github.com/powmedia/backbone-forms/blob/master/distribution/editors/list.js#L529

To relay the event.

Im currently using event.target.name to get the variable, Is there a better way to do this ?

This way assumes the element always has the name attribute the same as the variable name, Not sure if this is a safe way to get it

exussum12 avatar Feb 05 '14 12:02 exussum12

Can't remember off hand what the event names were (will need to check later) but probably either listName:item:change or listName:change:item; is anyone else using the List editor and know?

powmedia avatar Feb 05 '14 14:02 powmedia

Its listName:item:change for a text list type. For a nested model, the events are not passed on.

 form.on('all', function (functionName) {
    console.log(functionName);
 }

Shows nothing when the items inside the editor are updated

exussum12 avatar Feb 05 '14 15:02 exussum12

The events bubble up only to the direct parent form. For nested form (forms in modal list) you can do like that:

this.form.fields.listFieldName.editor.on('item:open', function(listEditor, itemEditor) { // when the modal is opened
    itemEditor.modalForm.fields.subFieldName.editor.on('change', function(itemEditor) { // only now, we can subscribe to events!
         console.log(itemEditor.getValue());
    });
});

Grsmto avatar Apr 02 '14 11:04 Grsmto

item:open is not called, in fact, no events from a nested modal form at all are called before readyToAdd is triggered. Does anyone have a solution to this?

peny avatar Jul 29 '14 12:07 peny

item:open is not called but item:blur and item:close are called. this is because the

item.editor.on(...) event binding is not complete until the render function is run. the render function creates both the modal editor and calls the open editor function. the open editor function sends the trigger "item:open" but there is no listener yet bound

hope that makes some sense

AlJohri avatar Sep 14 '15 19:09 AlJohri

@Grsmto

I was able to run the code you suggested above but I was wondering if you had any insight into why the "all" event wouldn't get called.

Works:

itemEditor.modalForm.fields.year.editor.on('change', function(itemEditor) {
    console.log(itemEditor.getValue());
});

Doesn't Work:

itemEditor.modalForm.on('all'), function(event) {
    console.log("blah" + event);
}

AlJohri avatar Sep 16 '15 15:09 AlJohri

It's been a while I didn't work with Backbone Forms but I don't remind any all event? Does it actually support it?

Grsmto avatar Sep 16 '15 15:09 Grsmto

It's been a while I didn't work with Backbone Forms but I don't remind any all event? Does it actually support it?

I'm pretty sure it doesn't.

Edit: at least there's no trace about it in Backbone Forms' code. Currently, every event triggered from BBForms is done via the trigger function in form.js which ends up calling Backbone.View.prototype.trigger. I looked a bit in Backbone's annotated source code, couldn't find something in two minutes and I have to leave... So sorry, not helping much in the end.

fonji avatar Sep 16 '15 15:09 fonji

All good, thanks for the quick responses guys!

AlJohri avatar Sep 16 '15 20:09 AlJohri