Closed (fixed)
Project:
Ajax
Version:
6.x-1.4
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
2 Jun 2009 at 16:21 UTC
Updated:
4 Feb 2012 at 08:20 UTC
I have a formblock with an ajax form on my page.
I can click the submit button, and it submits and outputs a message. Great.
How can I get it to submit with javascript.
I've tried:
$(#edit-submit-3).trigger('click');
$(#edit-submit-3).trigger('submit');
Neither of which works. What's the correct way to get the module to submit. Thank you.
Comments
Comment #1
ManyNancy commentedComment #2
kvvnn commentedCan you please explain how you made this work?
Comment #3
kvvnn commentedI am closing since this is a javascript issue and has nothing to do with Ajax module.
I'm not sure how to make it work.
Comment #4
melchior commentedThis one drives me crazy.
I've got exactly the same issue triggering a form by javascript when multiple forms are existing.
I also like trigger like ManyNancy with sth like: $(#edit-submit-1).trigger('click');
I found out that the problem lies here (ajax.js):
---------
f.each(function(){
this.ajax_activator = null;
$(this).submit(function(){
alert('submitform');
//console.error ("submit");
if (this.ajax_activator === null) {
alert("nok");
this.ajax_activator = $('#edit-submit', this);
}
if (this.ajax_activator.hasClass('ajax-trigger')) {
alert("ok");
Drupal.Ajax.go($(this), this.ajax_activator);
return false;
}
else {
return true;
}
if (this.ajax_activator === null) {
is always null when using s.click () or s.trigger('onclick');
if only one form exists it works, because the fallback " this.ajax_activator = $('#edit-submit', this); " take place
can anybody help please? I didn't get it :(
thhxx,
melchior
Comment #5
melchior commentedComment #6
ManyNancy commentedSry, no idea tbh. I did a workaround previously, using the clicking on the save button to trigger my other events, but still need this.
Comment #7
melchior commentedcan you tell me more details about your workaround?
I tried everything thinkable to get it working but failed all time :(
Comment #8
ManyNancy commentedAll I did was change my node creation workflow to include manually clicking the save button, replacing earlier steps in the workflow.
Comment #9
kvvnn commentedmelchlor : This is NOT an ajax module issue, but a javascript issue in general.
If you find a solution, please post :D
Comment #10
ManyNancy commented@kevin riggen, wut.
Yes it is an ajax module problem, what are you on? In fact #4 explains why.
Comment #11
kvvnn commented@ManyNancy
(Ignoring your irritating reply to me)
From everything I've tried and researched, the below link sums up what happens when you try and submit a form using javascript:
http://stackoverflow.com/questions/645555/should-jquerys-form-submit-not...
Simply put, any actions that are triggered when the Submit button is clicked by the user DO NOT GO THROUGH when using a javascript submit() or click() event.
Are you saying that this is not true?
Regarding #4, I'm not sure what he meant by "this works when there is only 1 form", as I've tried it with only 1 form in many cases. Have you?
The only solution I know of is to hijack the form's "action" attribute and use a jQuery ajax() call by yourself.
Comment #12
ManyNancy commentedThat doesn't make it a general js question. Since the submit event is not fired, ajax module should provide us with another event to trigger.
Comment #13
bartclarkson commentedI might not have the same use case as others on this thread, but I'm pretty sure it's the same. Here's what I did (having wrapped my ajax form in <div id="palette-form" /> for my own particular ends).
<script type="text/javascript">
Drupal.Ajax.go($('#palette-form #node-form'), $('#palette-form #edit-submit'));
</script>
The first argument is the formObj, the second is the submitter. This allows you to get your hands on the wonderful a_ajaxSubmit() function. See Drupal.Ajax.go @sites/all/modules/ajax/ajax.js; line 83; (v6.x-1.4) for more information.
Comment #14
Shadi.Alian commentedthnx for that, and it works without rapping the form
Drupal.Ajax.go($('#node-form'), $('#edit-submit'));
Comment #15
arski commentedwow, so nice! thanks so much for that suggestion! was trying to force click() and submit() and was getting some blank page with what appeared to be ajax module's config options in return.. go() works very nicely indeed.
Comment #16
brendoncrawford commented