List editor not sending events
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
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
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?
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
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());
});
});
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?
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
@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);
}
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?
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.
All good, thanks for the quick responses guys!