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

fix(input): false is no longer an empty value by default #4153

Closed

Conversation

petebacondarwin
Copy link
Contributor

This builds upon and improves @lgalfaso's PR #3658, without resorting to hard-coding fixes across directives.

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 #3490, #3658, #2594

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

`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
@lgalfaso
Copy link
Contributor

Nice patch!

@pkozlowski-opensource
Copy link
Member

+1, very nice

@IgorMinar
Copy link
Contributor

Wouldn't it be possible to provide an API for this that doesn't require monkey-patching? This functionality is needed, but I'm not keen on the API you created.

@petebacondarwin
Copy link
Contributor Author

@IgorMinar - can you give some more detail? There is no monkey patching going on here. Instead, I am creating an interface that allows input directives to specify what it means to them to be "empty".

This is done through the polymorphic method $isEmpty() on ngModelController, in just the same way that directives can provide their own version of $render().

@petebacondarwin
Copy link
Contributor Author

OK, so I guess, strictly, it is monkey patching individual instances of ngModelController but this is exactly what $render() does too.

@ghost ghost assigned IgorMinar and vojtajina Oct 2, 2013
@vojtajina
Copy link
Contributor

@petebacondarwin the isEmpty does not have to be exposed on the controller. How about if we only keep the local isEmpty and the directives that need a different implementation will use their own.

@vojtajina
Copy link
Contributor

Ignore my previous comment, I just realized that ng-required needs to read it.

@vojtajina
Copy link
Contributor

@petebacondarwin how about this vojtajina@c44fcb6 (it's one commit on the top of your PR)

@vojtajina
Copy link
Contributor

Made some little tweaks and merged as b56b21a.

@vojtajina vojtajina closed this Oct 8, 2013
@petebacondarwin
Copy link
Contributor Author

@vojtajina - Great! Thanks.

@petebacondarwin petebacondarwin deleted the empty-input-values branch February 11, 2014 09:55
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
6 participants