Simulated click on “add more value” button of multi value cck field causes whole content form to submit

扶醉桌前 提交于 2019-12-12 04:31:29

问题


Hi I have a multi value cck field in my cck content type. I want to simulate click on "add another item" using jquery. which is like

$('#edit-field-supp-quan-field-supp-quan-add-more').trigger('click');

but it causes whole content form to submit instead of adding extra multi value cck field.

Manuall clicks are working perfectly. Can anyone tell me why behavior of manual clicks and simulated clicks are different. thanks

----Update ---- This is the code I was using:-

$('#edit-field-freightamount-0-value').click(function(){

alert('hello');

$('#edit-field-supp-quan-field-supp-quan-add-more').trigger('click');

//$('.form-submit ahah-processed').trigger('click');

});

I actually intended to call this from inside some other function but I just wanted to test it before that . So i wrote this dummy function which is like if i click inside a texrfield it should simulate a click on "add more item"

How do we prevent default action of click?


回答1:


had the same problem. The answer is simple enough, use mousedown instead of click :)

$('#edit-field-supp-quan-field-supp-quan-add-more').trigger('mousedown');



回答2:


Try

return false;

at the end of your click function.




回答3:


Change

$('#edit-field-freightamount-0-value').click(function(){

to

$('#edit-field-freightamount-0-value').click(function(e){

then put

e.preventDefault();

in the click handler function.



来源:https://stackoverflow.com/questions/2788393/simulated-click-on-add-more-value-button-of-multi-value-cck-field-causes-whole

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!