html - AngularJS validation input diffrent than zero -
starting i'm realy new in progrraming especialy angular. want validate input not allow number 0 . here code:
<form ng-app="linearequation" ng-controller="calcctrl" name="calculator" ng-init="notvalid=true" novalidate> <div> <h3 class="field">kalkulator oblicza wartość równania <var>ax = b</var>.</h3> <div class="field"> <p> podaj wartość a:<br/> <input type="number" name="fielda" ng-model="a" required integer /> <span class="error" ng-show="calculator.fielda.$invalid"/> <span ng-show="calculator.fielda.$error.number"> proszę podać liczbę</span><br/> </p> <p> podaj wartość b:<br/> <input type="number" name="fieldb" ng-model="b" required integer /> <span class="error" ng-show="calculator.fieldb.$invalid"/> <span ng-show="calculator.fieldb.$error.number"> proszę podać liczbę</span> </p> <p> <button type="submit" ng-disabled=" calculator.fielda.$dirty && calculator.fielda.$invalid || calculator.fieldb.$dirty && calculator.fieldb.$invalid" ng-click="count()"> oblicz </button> </p> </div> <p class="field" id="result">x = {{c.tofixed(2)}}</p> </div>
how should validate it. button doesn't seem disabled on load of page. how manage this? answerws.
you should remove both $dirty
if want button disabled on start. , better use ng-pattern
directive validate numbers 1-9 , omit "0". input
should that:
<input type="number" name="fielda" ng-model="a" required ng-pattern="/[1-9]/" />
Comments
Post a Comment