0

Datepicker gets date and puts it into input field. Input marked as required but AngularJS cannot see changes and mark it as valid. Why?

HTML

<div class="form-group" ng-class="{ 'has-error': myForm.inputDatetimeStart.$invalid }">
    <label for="datetimepicker_start" class="col-sm-3 control-label">Start date and time: </label>
    <div class="col-sm-8">
        <input class="form-control" name="inputDatetimeStart" ng-model="datetime_start" id="datetimepicker_start" type="text" required>
    </div>
</div>

JS

 angular.module('myApp', ['ajoslin.promise-tracker', 'ngRoute'])
     .controller('myCtrl', function ($scope, $http, $log, promiseTracker, $timeout){
       jQuery('#datetimepicker_start').datetimepicker({   });
       ...

     }
2
  • 1
    Because what the jQuery datepicker is doing when it updates the input box is not "seen" by Angular. If you want it to work correctly, you should create a directive that wraps the jQuery datetimepicker functionality and then sends the proper events and/or scope $applys when the jQuery datepicker library does something Commented Sep 23, 2014 at 13:08
  • Can you please provide example code? Commented Sep 23, 2014 at 13:57

1 Answer 1

1

Try to use

$scope.$watch('datetime_start', function () { 
    $scope.$apply();
})

it will make a digest cycle occur.

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.