How to get ui.bootstrap timepicker to pass the test by default, without user interaction

When the timepicker control is inside the form and has an initial "valid" default value, it must be checked, and it $scope.formname.$validmust be true. However, I see that if the user does not interact with the control, it is not checked and the form is not in the correct state, this is unacceptable, since the user may not even want to change the default time value. Any ideas on what angular can do to validate the control with its default value and shape, respectively.

https://plnkr.co/edit/p1I2NoNpg3XMzijHUadi?p=preview

<form name="myForm" novalidate>
  <uib-timepicker ng-model="time" template-url="timepicker.html" hour-step="1" ng-required="true" minute-step="1" show-meridian="false" ></uib-timepicker>

  <input type="submit" value="Form state" ng-click="alertState()"></button>
</form>




 var app =  angular.module('demo',['ui.bootstrap']);


  app.controller('myCtrl',[ '$scope', function($scope) {



  $scope.alertState = function() {
    alert($scope.myForm.$valid);
  };

  }]); 
+4

Source: https://habr.com/ru/post/1622394/


All Articles