Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#33312] Also calls jQuery events on form submission #3484

Closed
wants to merge 5 commits into from
Closed

[#33312] Also calls jQuery events on form submission #3484

wants to merge 5 commits into from

Conversation

fredden
Copy link
Contributor

@fredden fredden commented Apr 22, 2014

This means that the event listeners in the HTML5-fallback library (which use jQuery) are also triggered. See JoomlaCode issue: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33312

@fredden fredden changed the title Also calls jQuery events on form submission [#33312] Also calls jQuery events on form submission Apr 22, 2014
@beat
Copy link
Contributor

beat commented Apr 22, 2014

If you want to do this jQuery-correct way, you should call $(form.classOfForm).submit(); This allows to prevent the default form submit if wanted (e.g. for validations):

http://api.jquery.com/submit/

@dgrammatiko
Copy link
Contributor

@test success
Needs also the same mods in the compressed file!

Test instructions:
Apply patch
Enable debug
Open /administrator/components/com_content/views/article/tmpl/edit.php
and insert

JFactory::getDocument()->addScriptDeclaration('
jQuery(document).ready(function() {
    jQuery("#item-form").bind("submit", function() {
        console.log("works");
    });
});
');

just before ? > at around line 75

Try to create (save) an article, you should get in browsers log works

screen shot 2015-03-09 at 12 35 57

@dgrammatiko
Copy link
Contributor

@fredden Can you update the code as it says that there are conflicts?
Also can you apply the mod to the compressed file?

@fredden
Copy link
Contributor Author

fredden commented Mar 9, 2015

Okay, I've updated this pull request. Hopefully that's the correct procedure.
I've not tested this on a real site, but the Travis CI build passed.

@dgrammatiko
Copy link
Contributor

This form.classOfForm doesn’t work. Sorry I should have comment on that before, as I tried that recommendation but I forgot to write about it!

@fredden
Copy link
Contributor Author

fredden commented Mar 9, 2015

Thanks. Ideally I'd have tested before committing. Updated per your example @dgt41, still untested by me.

@dgrammatiko
Copy link
Contributor

@Fedik @anibalsanchez can you take a look at this one?
@beat did you mean something like this:

        var formClass = jQuery(form).attr("class");
        jQuery(form, "."+formClass).submit();

?

@Fedik
Copy link
Member

Fedik commented Mar 9, 2015

in theory should be enough just jQuery(form).submit() or jQuery(form).trigger('submit');.
I do not know what the reason to use some tricky formClass, the form could be without any class

@dgrammatiko
Copy link
Contributor

@Fedik This works with no problems for me as well, but @beat mentioned that an extra class selector should be in place. I think this is not necessary as we are triggering the event for a specific object, so I don’t see how this can conflict somehow with, lets say another form in the page...

@Fedik
Copy link
Member

Fedik commented Mar 9, 2015

well, I do not see info that can confirm it on http://api.jquery.com/submit/
quick test show that it will not work, and form will be submitted when you trigger submit event on form element ... unless I missed something 😄

@dgrammatiko
Copy link
Contributor

This allows to prevent the default form submit if wanted

That was the exact reason @beat mentioned in the comment above, but I am not sure what he means or how this can be tested!

@Fedik
Copy link
Member

Fedik commented Mar 9, 2015

This allows to prevent the default form submit if wanted

this do not prevent, just try 😉

Maybe something like this can only trigger, and then submit by form.submit():

if(jquery){
  jQuery(form).submit(function (event) {
    event.preventDefault();
  });
  jQuery(form).submit();
}
form.submit()

but I do not see much sense it this 😄

@anibalsanchez
Copy link
Contributor

I concur, no need of tricky formClass. Besides, I could have to add more classes.

@dgrammatiko
Copy link
Contributor

So @Fedik @anibalsanchez @beat we all agree that this formClass is not needed?
@fredden Can I ask you to revert this without my and @beat ’s suggestion?

@dgrammatiko
Copy link
Contributor

@Fedik @anibalsanchez can you test it? @fredden reverted to the original jQuery(form).submit();

@Fedik
Copy link
Member

Fedik commented Mar 10, 2015

test works good for me

@zero-24
Copy link
Contributor

zero-24 commented Mar 10, 2015

RTC based on testing Thanks!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3484.

@brianteeman brianteeman added the RTC This Pull Request is Ready To Commit label Mar 13, 2015
@mbabker mbabker added this to the Joomla! 3.4.1 milestone Mar 15, 2015
@mbabker mbabker closed this in 76fe9a1 Mar 15, 2015
@dgrammatiko
Copy link
Contributor

@mbabker It seems that the solution provided here doesn’t work for all cases e.g. #6207 (last comments)
Do we need a new PR to change it to jQuery(form).trigger("submit"); or this can be done here?

@mbabker
Copy link
Contributor

mbabker commented Mar 25, 2015

Do it as a PR please. I manually merged this one due to conflicts and had to triple check myself when merging the compressed file changes; at least a PR (hopefully) has the right changes 😃

@dgrammatiko
Copy link
Contributor

ok will do that

@Fedik Fedik mentioned this pull request Mar 26, 2015
@zero-24 zero-24 removed the RTC This Pull Request is Ready To Commit label Oct 14, 2015
@fredden fredden deleted the patch-1 branch April 8, 2016 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants