xuijs / xui

A tiny javascript framework for mobile web apps.
http://xuijs.com
787 stars 106 forks source link

Getting value of form element with .value is empty using .submit() #46

Closed liamgooding closed 12 years ago

liamgooding commented 12 years ago

using the .submit() listener for a form

x$('#form-id').submit(function(){
    console.log(document.getElementById('input-id').value);  // correctly gets value
    console.log(x$('#input-id').attr('value'));  // gives undefined
    console.log(x$('#input-id').value);  // gives undefined
});
filmaj commented 12 years ago

Can you post the markup, or show full code for a test? What kind of element is it with id "input-id"?

ghost commented 12 years ago

I can confirm this issue, but I only tested this on the Android emulator.

Javascript: x$("#buttont").click(function (element) { alert(x$("#p").attr("value")); });

Html 1: <input type="password" id="p" name="p" />

Html 2: <input type="password" id="p" name="p" value="test" />

When run with "Html 1", always returns an empty string (""). When run with "Html 2", always returns "test", no matter if the values in the field has changed.

filmaj commented 12 years ago

Thank you, I'll check this out as soon as I get a chance

ghost commented 12 years ago

I get this problem on mobile safari and chrome because the "tagName" of the element returned by x$('#button') is "INPUT" and not what the code is == to "input".

$ diff xui-2.2.0.js xui-2.2.0-mod.js 
555c555
<                 if (el.tagName == 'input' && attribute == 'value') el.value = val;
---
>                 if (el.tagName.toLowerCase() == 'input' && attribute == 'value') el.value = val;
564c564
<                 if (el.tagName == 'input' && attribute == 'value') attrs.push(el.value);
---
>                 if (el.tagName.toLowerCase() == 'input' && attribute == 'value') attrs.push(el.value);
filmaj commented 12 years ago

Now fixed in 1f2cdda - also added specs for this. Thanks guys!