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

number input filter is not working if we clear the value #10230

Open
webtunings opened this issue Nov 26, 2014 · 5 comments
Open

number input filter is not working if we clear the value #10230

webtunings opened this issue Nov 26, 2014 · 5 comments

Comments

@webtunings
Copy link

if we clear the number input value(make it empty) ideally filter shouldn't be applied and all values should be listed. Right now if we apply some filter by putting number lets say 5 in input box it works fine and all data matching 5 is listed down. Now if we clear the value in input box, ideally all values should be listed (no filter) but angular applies null filter for numbers and everything is filtered out (ng-repeat doesn't list anything).

input type="number" ng-model="age"

filter:age

Note: No issue with type=text input

@gkalpak
Copy link
Member

gkalpak commented Nov 26, 2014

(As you mentioned) this happens because input[number] assigns null to the model when the field is empty.

Expecting this to work the way you expect it to is reasonable (imo), but I am not sure how we could address this.
Fixing it on the filter side is not desirable, because null can be a valid value to look for (and we can't treat it as undefined). Fixing it on the NgModelController is probably not a viable solution either.

@Others: Thoughts ?

In the meantime, you could use this (not so beautiful) work-around:

<input type="number" ng-model="search.posts" />
...
<div ng-repeat="user in users | filter:((search.posts===null)?undefined:search)">...</div

Demo fiddle

@Narretz
Copy link
Contributor

Narretz commented Nov 26, 2014

We return null because returning undefined from a parser sets a parse error. Another reason why that is not the best design.

@pkozlowski-opensource
Copy link
Member

@Narretz I was about to ask why we don't return undefined :-)

@thbox
Copy link

thbox commented Dec 10, 2014

I know this post is kinda old but i had a really bad time figuring out how to solve this problem so I want to share my solution. Add a oninput event to your input field and in the javascript function check if the value of this field is an empty string, if so delete the value of the input field with:
delete document.getElementById('whatever').value;

@caitp
Copy link
Contributor

caitp commented Dec 10, 2014

I don't think HTMLInputElement attributes are supposed to be configurable

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

No branches or pull requests

6 participants