Checkbox and the #set method
Reported by MadRabbit | January 6th, 2010 @ 10:31 PM | in 1.5.3 Release
seems like it doesn't work with checkboxes
$('that-box').set('checked', true);
ain't producing anything in webkit. needs some investiation
Comments and changes to this ticket
-
Douwe M. January 7th, 2010 @ 02:40 PM
Apparently WebKit doesn't like
element.checked = true;
element.setAttribute('checked', 'checked');
-
MadRabbit January 7th, 2010 @ 03:23 PM
I didn't investigated the problem yet, but I think element.checked = true; is working, it have to. the problem is probably in the way how the #set method works.
-
Douwe M. January 7th, 2010 @ 05:42 PM
Well,
a = document.createElement('input'); a.setAttribute('type', 'checkbox'); a.checked = true;
<input type="checkbox">
, where
a = document.createElement('input'); a.setAttribute('type', 'checkbox'); a.setAttribute('checked', 'checked');
<input type="checkbox" checked="checked">
, as expected. -
MadRabbit January 7th, 2010 @ 06:07 PM
There is a difference for input elements between a value/state assignment and attribute settings. You can change the element value, but the attribute will be the same, which is basically used for form resets. but if you don't change the attribute, it doesn't mean that you won't change the actual value.
so in that case
a = document.createElement('input');
a.type = 'checkbox';
a.checked = true;although you won't see the attributes, it still will be a checkbox and it will be checked. Same if you would do it with a normal input element
a = document.createElement('input');
a.type = 'text';
a.name = 'name';
a.value = 'bla bla bla';when you insert this on the page you'll see "" in the content, but in reality, your input element will have all the correct name, value and type, which will be used if you submit a form.
Don't worry about that, this ticket is a simple fix, just the #get method is a performance sensitive part, and I'll need to do some regressive testing first.
-
Douwe M. January 7th, 2010 @ 06:17 PM
Hmm, I feel really stupid now... :-( I know all of this, but for some reason I didn't think of it :|
But have you found the cause for this problem?
-
MadRabbit January 7th, 2010 @ 06:24 PM
I think it's because my #set method don't convert data in strings, so when you say #set('checked', true) it will call
element.setAttribute('checked', true); and that probably causes the problem.I could make it simply element.setAttribute('checked', ''+value); but not sure if it's the most efficient way of doing that
-
Douwe M. January 7th, 2010 @ 06:30 PM
This is definition for the Element#set method:
set: function(hash, value) {
if (value) { var val = {}; val[hash] = value; hash = val; } for (var key in hash) { // some attributes are not available as properties if (this[key] === undefined) { this.setAttribute(key, ''+hash[key]); } this[key] = hash[key]; } return this;
}this['checked']
isn't undefined, i.e. is an available property, which it is, and thus doesn't even get to thethis.setAttribute
part, it only setsthis['checked']
totrue
.This means you're guess is incorrect :P Unless my brain is screwing up again...
-
MadRabbit January 7th, 2010 @ 07:01 PM
Well, that's why it's called a "guess", if I knew for sure I would probably just fixed it
I'm not sure what's the problem and if there is a problem at all. I'm busy with the documentation now and don't want to deal with it now, I had run in an issue in some script and simply created the ticket, so that I didn't forget about it later.
-
Douwe M. January 7th, 2010 @ 07:04 PM
Yeah, that's true. But guesses are most of the time, well, guesses to what the problem could be. I'm just trying to help you by pointing out one isn't very probable :-)
-
MadRabbit January 7th, 2010 @ 07:13 PM
I know, you're doing fine. Just I cannot do all the things at once 8)
If you're interested in the bug and have time, you could investigate it, maybe there is no bug at all and it was just me getting screwed with that my script.
write couple of scripts setting the property to true and false, with the constructor and with the method, and run them in different browsers, see what will happen.
-
MadRabbit January 8th, 2010 @ 01:07 PM
- State changed from new to resolved
okay, the problem was that I was trying to set the 'checked' value to 'false' like that
$('checkbox').set('checked', false);
and then the front converter
if (value) { var val = {}; val[hash] = value; hash = val; }
didn't convert the two variable arguments into a hash, because had a boolean check. i've changed it for
if (typeof(hash) === 'string') ....
and now it works fine
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.