2

Is there an easy way to have input[number] directive accept a blank value?

I basically need to an input that accepts 1 - 100 but also a blank value. Hoping there's an easy way to do it without making a custom validator just for this.

https://docs.angularjs.org/api/ng/input/input%5Bnumber%5D this is the built in Angular directive.

3
  • Confusing question whats input[number] Commented Mar 21, 2016 at 23:41
  • @Dsafds: I'm assuming he means input[type="number"] -> <input type="number" /> Commented Mar 21, 2016 at 23:54
  • Then his question dosent make any sense? @DMan Commented Mar 21, 2016 at 23:55

1 Answer 1

1

inputs by default allow empty values (given required and ng-required are not set):

<input type="number" min="1" max="100" ng-model="val">

<!DOCTYPE html>
<html>

<head>
  <script data-require="[email protected]" data-semver="1.5.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
</head>

<body ng-app>
  <form name="f">
    <input type="number" min="1" max="100" ng-model="val" name="in">
    <b>val:</b> '{{val}}' <b>valid:</b> {{f.in.$valid}}
    <button ng-click="val = ''">Clear</button>
  </form>
</body>

</html>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.