This project is archived and is in readonly mode.

#797 ✓invalid
raider5

toQueryString() incorrect behaviour

Reported by raider5 | November 27th, 2009 @ 11:50 AM | in 1.3.0 rc2 (closed)

Hi,

As of version 1.2.3 toQueryString ignores values on submit elements, see:

https://mootools.lighthouseapp.com/projects/2706/tickets/664-toquer...

While the initial behaviour of sending all submit button values was incorrect, the behaviour used now of ignoring all submit button values is also incorrect. The correct behaviour is to send the value of whatever submit button was clicked. Code that has logic based on the value of submit is now broken.

I appreciate this isn't a trivial thing to fix, but I thought I'd raise the issue.

Thanks,

SJ

Comments and changes to this ticket

  • raider5

    raider5 November 27th, 2009 @ 01:32 PM

    Something like this works without changing core:

    
     $$('form').each(function(form) {
                    form.getElements('input').each(function(el) {
                        if (el.type == 'submit') {
                            el.addEvent('click', function(ev) {
                                new Element('input', { type: 'hidden', name: this.name || this.id, id: this.id || this.name, value: this.value}).inject(form);
                            });
                        }
                    });
                });
    
  • raider5

    raider5 December 11th, 2009 @ 10:58 AM

    Had an issue with the code posted above, forms that are posted without using MooTools would be sent the button value twice, once from the button, and once from the hidden field that has been added dynamically. The code below addresses this by removing the name property of the button when adding the hidden field:

    
    $$('form').each(function(form) {
        form.getElements('input').each(function(el) {
            if (el.type == 'submit') {
                el.addEvent('click', function(ev) {
                    new Element('input', { type: 'hidden', name: this.name || this.id, id: this.id || this.name, value: this.value }).inject(form);
                    this.removeProperty('name');
                });
            }
        });
    });
    
  • fakedarren

    fakedarren February 8th, 2010 @ 06:48 PM

    • State changed from “new” to “open”
    • Assigned user set to “fakedarren”
    • Milestone changed from 2.0 to 1.3.0 rc2

    raider5 - I have a lot of issues assigned to me at the moment - is there any chance you can provide a mooshell (http://mootools.net/shell) example of this? It would help me a lot.

    Cheers
    Darren

  • raider5

    raider5 February 10th, 2010 @ 02:33 PM

    Hi Darren,

    Here is a quick mooshell example to demonstrate the issue and also a fix we're using that doesn't affect core:

    http://mootools.net/shell/PdzRN/

    Cheers,

    SJ

  • fakedarren

    fakedarren February 10th, 2010 @ 02:36 PM

    That's great, thanks. Will look into it.

  • Fábio M. Costa

    Fábio M. Costa February 11th, 2010 @ 01:18 AM

    IMHO this should be a plugin. Or maybe added to the set('send') method?

  • fakedarren

    fakedarren February 11th, 2010 @ 01:26 AM

    I haven't investigated this yet but.

    Thoughts on this are that moo Ajax post methods should recreate standard postback. Or get or whatever. Form submissions through HTTP or Ajax.

    In standard postback you can have multiple submit buttons hence why submit button values are submitted. It shows what was clicked.

    As nothing was clicked, I feel it is down to the user to explicitly define this as an Ajax equivalent of standard postback. Or define an Ajax post on submit.

    Thoughts?

  • fakedarren

    fakedarren February 14th, 2010 @ 11:59 AM

    • State changed from “open” to “invalid”

    Sorry, I'm closing this as I don't believe it belongs in core. If you feel this is not the correct decision, please comment to that effect and we can continue the discussion.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages