Trigger Change Events after newly created nodes are referenced
cYu - March 19, 2009 - 19:50
| Project: | Popups: Add and Reference |
| Version: | 6.x-2.0-alpha1 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I'm working on an inline references module that will load referenced node content and allow pop-up editing of that content, but I'm having trouble firing js after a new node is created and then referenced. Since I can't control order of execution for events bound to popups_form_success, it would be best for me if popups: add and reference triggered .change() after updating a reference value and I bound my functionality to the change event. Other modules reacting off of a nodereference field value changing would benefit from this as well.
| Attachment | Size |
|---|---|
| trigger_change.patch | 1.56 KB |

#1
Bah, I guess it isn't as easy as I was trying to make it. When .find() finds nothing and then .end().change() is fired it will throw JS errors. My jquery chops are a bit lacking, so I don't know the best way of making this happen conditionally.
#2
#3
Is something like this sensible?
#4
Interesting.
Can't you just bind an onChange trigger to the elements directly in your custom code?
#5
Yes, my code is bound to change() but without this patch it is not fired after a new nodereference is created in popups: add and reference. I thought it would, but doing something like
$emptyAutos.eq(0).val(title);to change the input's value will not fire the change event, which is what this patch would explicitly do after form element values are set.
#6
Ok, that totally makes sense.
If you can change the patch to be against 2.0-alpha1 (the 1.0 branch is closed to new features), and try extracting
function() {+ if (this) {
+ this.change();
+ }
into a stand alone function, to keep the code neat, I will put it into 2.0-alpha2.
Thanks,
-t
#7
Ok, I've moved that code into it's own function. My testing indicated that .end() was not needed in the places I was using it so I removed those calls.