kineticsocial / angularjs-datetime-picker

AngularJS DateTime Picker Without JQuery and Bootstrap
MIT License
66 stars 79 forks source link

Angular Form Properties not affected when selecting a date #20

Open danielforsberg opened 8 years ago

danielforsberg commented 8 years ago

As topic states the form properties is not affected when I choose a date (Google Chrome Version 50.0.2661.86 (64-bit))

Here's what I am trying to do:

        <form name="form">
                <input ng-model="model"
                       name="dateTime"
                       datetime-picker
                       date-format="yyyy-MM-dd HH:mm:ss"
                       close-on-select="true" />
            <span ng-show="form.dateTime.$dirty" class="notice">{{ message }}</span>
        </form>

The message only shows if I manually make some input to the field, not when choosing a date from the datetime-picker

thethakuri commented 8 years ago

Try : <span ng-show="!form.dateTime.$pristine" class="notice">{{ message }}</span>

danielforsberg commented 8 years ago

Thanks for the input but I get the same result.

ryan-morris commented 8 years ago

We are seeing the same issue. I made a small change that seems to work but I do not know if this is the best fix. Any thoughts?

var datetimePicker  = function($parse, DatetimePicker) {
    return {
      // An ngModel is required to get the controller argument
      require: 'ngModel',
      link: function(scope, element, attrs, ctrl) {
        // Attach validation watcher
        scope.$watch(attrs.ngModel, function(value, old) {
          //force dirty on update
          if (value !== old) {
            ctrl.$setDirty();
          }
danielforsberg commented 8 years ago

Thank you @ryan-morris for your input, it works. I'm not sure if it's the right way to do it either but I will use it until further notice.