I have an input type number. I want to set default value 1 if ng-model is null or empty or undefined. it works fine. But on the same page, I have a submit button. on click of this button, I'm just returning false for some validation fail. But when it returns after validation fails. my dropdown (input type number) shows empty value. I check the value of ng-model, it's empty.
So if the value is not a proper number, I want it to set to 1 by default.
<input type="number" step="1" min="1" onkeypress="return (event.charCode == 8 || event.charCode == 0) ? '': event.charCode >= 48 && event.charCode <= 57" id="train_n_file"
ng-init="item.n_fold = item.n_fold || 1" ng-model="item.n_fold" ng-disabled="item.train_select=='training_time_range'" style="margin-top: -2px;" class="input-div" value="{{1}}">
<md-button ng-click="schedule_event()" type=submit id="step-btn" class="build-model md-raised step-btn md-primary md-button md-ink-ripple"> Schedule </md-button>
$scope.schedule_event = function () {
if (some condition) {
$scope.showAlert('Please pick schedule frequency.');
return false;
}
onkeypressin there? Settingtype="number"prevents entry of non-numeric values. You also shouldn't have avalueattribute if you're usingng-model. Sounds like most of this should be handled in your model or controller.<input>field value ,do the necessary validation and updates themodelvalue of<input>field.