Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

select won't work when required attr is set and option's value is false #2436

Closed
rexpan opened this issue Apr 18, 2013 · 6 comments
Closed

Comments

@rexpan
Copy link

rexpan commented Apr 18, 2013

example of problem

<select ng-model="bValue"
          ng-options="o.value as o.text for o in options"
          required></select>
$scope.options = [{value:true, text:"Yes"}, {value:false, text:"No"}];

When choose "No", bValue is not set to false.

  • if remove required attr, it work as normally.
  • the "Yes" option works normally.
  • $scope.options = [{value:1, text:"Yes"}, {value:0, text:"No"}]; works normally.
@jkl1337
Copy link

jkl1337 commented May 7, 2013

Just ran into this as per implementation of required directive:

      var validator = function(value) {
        if (attr.required && (isEmpty(value) || value === false)) {

This seems a bit surprising for false to be interpreted as the absence of a model value. What was the rationale?

@jkl1337
Copy link

jkl1337 commented May 7, 2013

Answered my own question, I suppose. required treats false this way to work on checkboxes. Solution is to use a custom parser/formatter on the model and change view value to something not falsey (ie 0)

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@bschelberg
Copy link

This is still an issue (using v1.1.5).

@leafdropco
Copy link

Still an issue 1.4

@miteshpatekar
Copy link

Even I am facing the same issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants