Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

input[type=checkbox] and Form.Element#getValue

#196

When I run getValue() on an input[type=checkbox], what I expect to get is something to tell me whether the checkbox is checked or not.

What I get instead is, no matter what the checked state, the specified value of the input. This is in a way expected behavior, but I think it would be better to make the return value also say something about the checked state. Maybe it should return null or false when !checked, and the normal value when checked?

Reported by Douwe M. · February 16th, 2010 @ 01:49 PM

State: invalid
Milestone: none
Assigned to: nobody

Activity

  1. MadRabbit
    MadRabbit

    I thought about it designing the method and here is the thing.

    There might be several checkboxes and everyone of them will have different value. So we need that method, to return correct value of the checkbox, whether it checked or not, coz there are cases when you need the actual value regardless it's state.

    But your case have makes sense as well, and here is how you can deal with that. There is a form method called #values that returns a hash of the form values. That method filters out all the disabled and unchecked radio/checkbox inputs. So if you need the actual value that the form will send, you can do that kinda like that

    var value = $('my-input').form.values()['the_name'];
    

    if it's too long and ugly you always can define your own method for your application

    February 16th, 2010 @ 06:14 PM

  2. Douwe M.
    Douwe M.

    Yeah, I'm using something like that already, I just thought, maybe it would be a good idea to make the getValue() method act like this, but I see why that's not ideal either.

    February 16th, 2010 @ 06:20 PM

  3. MadRabbit
    MadRabbit
    • State changed from new to invalid

    yup. sometimes you have non-ideal choices only

    February 16th, 2010 @ 06:30 PM

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.