This project is archived and is in readonly mode.

#148 ✓invalid
Juri Kuehn

Request.send() skips input fields with empty values

Reported by Juri Kuehn | June 20th, 2008 @ 11:20 AM | in 2.0 (closed)

Calling the send() method on a Request object to submit a form results in iterating over all form elements and calling toQueryString() on each of them.

Problem: empty strings are not added to the query string

line 1610 of mootools-1.2-core-nc.js:

if (val) queryString.push(el.name + '=' + encodeURIComponent(val));

empty string (val) is evaluated to false and thus not added to the

querystring

This does not conform to the default browser and mootools 1.1 behaviour, where all fields are send to the server, empty or not.

We are generating many fields dynamically and need them posted back to the server, to see which fields were edited by the user.

I see that in many cases it makes sense not to post empty values. So if this is a feature and not a bug, maybe we can add an option "skipempty" which defaults to true?

Thanks & best regards,

Juri

Comments and changes to this ticket

  • Juri Kuehn

    Juri Kuehn June 24th, 2008 @ 11:25 AM

    • Assigned user cleared.

    Hi,

    i overlooked one thing, its definitely a bug, a small one though.

    In function Element.toQueryString(), line 1602 1.2 release, the value of the form-element is set to *null if the checkbox or radiobutton is not checked*, el.value is taken otherwise

    	toQueryString: function(){
    		var queryString = [];
    		this.getElements('input, select, textarea').each(function(el){
    			if (!el.name || el.disabled) return;
    			var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
    				return opt.value;
    			}) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
    			$splat(value).each(function(val){
    				if (val) queryString.push(el.name + '=' + encodeURIComponent(val));
    			});
    		});
    		return queryString.join('&');
    	},
    

    Problem: the check in line 1610 (if (val)) excludes not only not checked radioboxes and checkboxes, but also empty input fields, which is not default browser behaviour (and breaks 1.1 code).

    So the fix would be, to change the check from if (val) to if (val != null)

    				if (val) queryString.push(el.name + '=' + encodeURIComponent(val));
    

    to

    				if (val != null) queryString.push(el.name + '=' + encodeURIComponent(val));
    

    it would be very nice, if this could be included in the 1.2.1 bugfix release

    Thank you

  • Jan Kassens

    Jan Kassens July 5th, 2008 @ 09:31 PM

    • State changed from “new” to “invalid”
    • Tag set to 1.2, 1.2release, defect, minor, request

    duplicate of #169 (closing this as the other ticket contains more information)

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

Attachments

Pages