#196 ✓invalid
Douwe M.

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

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

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?

Comments and changes to this ticket

  • MadRabbit

    MadRabbit February 16th, 2010 @ 06:14 PM

    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

  • Douwe M.

    Douwe M. February 16th, 2010 @ 06:20 PM

    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.

  • MadRabbit

    MadRabbit February 16th, 2010 @ 06:30 PM

    • State changed from “new” to “invalid”

    yup. sometimes you have non-ideal choices only

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.

New-ticket Create new ticket

Create your profile

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

RightJS Core Tickets

Shared Ticket Bins

People watching this ticket

Pages