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

fix(required): false is a valid model value for required <select> #3658

Closed
wants to merge 1 commit into from

Conversation

lgalfaso
Copy link
Contributor

Make the required directive accept the model value false when it is not an element.

Closes #3490

@ghost ghost assigned mhevery Aug 27, 2013
@@ -1228,14 +1228,15 @@ var requiredDirective = function() {
attr.required = true; // force truthy in case we are on non input element

var validator = function(value) {
if (attr.required && (isEmpty(value) || value === false)) {
if (attr.required && (isEmpty(value) || !acceptFalse && value === false)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this condition ? why is false invalid for inputs ?

@ghost ghost assigned vojtajina Sep 5, 2013
@vojtajina
Copy link
Contributor

Thanks @lgalfaso. This change makes sense to me.

I only don't understand why we need to treat false specially on inputs.

@lgalfaso
Copy link
Contributor Author

lgalfaso commented Sep 5, 2013

Hi @vojtajina, input of type checkbox can have the values true or false. When ng-required is placed on an input of type checkbox, this implies that the checkbox must be checked

Make the `required` directive accept the model value `false` when it is
not an <input> element or when the <input> element is not a checkbox

Closes angular#3490 angular#2594
@petebacondarwin
Copy link
Member

@lgalfaso and @vojtajina - Can you take a look at this alternate solution to these problems?
#4153

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request Sep 25, 2013
`checkboxInputType` and `ngList` directives need to have special logic for whether
they are empty or not.  Previously this had been hard coded into their
own directives or the `ngRequired` directive.  This made it difficult to handle
these special cases.

This change factors out the question of whether an input is empty into a method
`$isEmpty` on the `ngModelController`.  The `ngRequired` directive now uses this
method when testing for validity and directives, such as `checkbox` or `ngList`
can override it to apply logic specific to their needs.

Closes angular#3490, angular#3658, angular#2594
@petebacondarwin
Copy link
Member

Moving discussion to #4153

vojtajina pushed a commit to vojtajina/angular.js that referenced this pull request Oct 7, 2013
`checkboxInputType` and `ngList` directives need to have special logic for whether
they are empty or not.  Previously this had been hard coded into their
own directives or the `ngRequired` directive.  This made it difficult to handle
these special cases.

This change factors out the question of whether an input is empty into a method
`$isEmpty` on the `ngModelController`.  The `ngRequired` directive now uses this
method when testing for validity and directives, such as `checkbox` or `ngList`
can override it to apply logic specific to their needs.

Closes angular#3490, angular#3658, angular#2594
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
`checkboxInputType` and `ngList` directives need to have special logic for whether
they are empty or not.  Previously this had been hard coded into their
own directives or the `ngRequired` directive.  This made it difficult to handle
these special cases.

This change factors out the question of whether an input is empty into a method
`$isEmpty` on the `ngModelController`.  The `ngRequired` directive now uses this
method when testing for validity and directives, such as `checkbox` or `ngList`
can override it to apply logic specific to their needs.

Closes angular#3490, angular#3658, angular#2594
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
`checkboxInputType` and `ngList` directives need to have special logic for whether
they are empty or not.  Previously this had been hard coded into their
own directives or the `ngRequired` directive.  This made it difficult to handle
these special cases.

This change factors out the question of whether an input is empty into a method
`$isEmpty` on the `ngModelController`.  The `ngRequired` directive now uses this
method when testing for validity and directives, such as `checkbox` or `ngList`
can override it to apply logic specific to their needs.

Closes angular#3490, angular#3658, angular#2594
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngOptions with boolean values breakes select element
4 participants