angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

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

Open rexpan opened this issue 13 years ago • 6 comments

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.

rexpan avatar Apr 18 '13 03:04 rexpan

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 avatar May 07 '13 04:05 jkl1337

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)

jkl1337 avatar May 07 '13 04:05 jkl1337

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!

btford avatar Aug 24 '13 00:08 btford

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

bschelberg avatar Aug 29 '13 02:08 bschelberg

Still an issue 1.4

Even I am facing the same issue.

miteshpatekar avatar Sep 23 '15 06:09 miteshpatekar