0
votes

I have a node add form with a field that has an 'add more' button. This particular field needs to be populated dynamically. Why doesn't it work to trigger a jquery click on the 'add more' button ($('#edit-field-roof-area-und-add-more').click();)? If I do that in the console, it returns an empty array.

What is the simplest way to create one or two fields in a node add form that I can add an unlimited amount to dynamically from the client side (the values come from a JS application.)

2
do you have an example jsfiddle or codepen so we can see exactly what your seeing to better help you? - Jonathan Marzullo

2 Answers

2
votes

found it!! jQuery('#edit-field-phone-no-und-add-more').trigger('mousedown') Also, the ID changes each time the button is clicked.

0
votes

when adding nodes you might want to look into using context in your handler:

$('#edit-field-roof-area-und-add-more', 'body').click();

since the elements i dynamically created after the DOM is loaded.. try that, since the body tag is already present in the DOM when the page loads

and/or provide a jsfiddle or codepen example to better help you more...

EDIT:

you could also try this jQuery trigger():

 $('#edit-field-roof-area-und-add-more', 'body').trigger("click");

or jQuery triggerHandler():

 $('#edit-field-roof-area-und-add-more', 'body').triggerHandler("click");

the difference between the two is that triggerHandler does not bubble up the DOM

also do have an example jsfiddle or codepen.. of your click event handler you are trying to trigger?