Git Product home page Git Product logo

Comments (10)

atais avatar atais commented on August 15, 2024

Hi.

I admit it can be somehow an undesirable 'feature', but to be honest, I did not encounter this problem before. I have done a fast check and from what I see, even if the date is not set the form gets instantly dirty.

If you need a walkaround... I would simpy add this to your controller.

$timeout(function() {
  $scope.dateForm.$setPristine();
});

It works with a plunker: http://plnkr.co/edit/L1HIMU

But to truly address this problem I would need to first find what causes the dirty state. Especially, if the problem lays in the wrapper or in the library.

At the moment I am not sure if I will have time to patch this (or find the source of an issue). Any PRs are welcome 😄

from angular-eonasdan-datetimepicker.

shustariov-andrey avatar shustariov-andrey commented on August 15, 2024

Problem lays within this line: https://github.com/atais/angular-eonasdan-datetimepicker/blob/master/dist/angular-eonasdan-datetimepicker.js#L29. When setting ngModel's view value, it becomes $dirty

from angular-eonasdan-datetimepicker.

atais avatar atais commented on August 15, 2024

Thanks @shustariov-andrey !

But well... it is a core line of this wrapper.

I can see there is a walkaround, fe. http://stackoverflow.com/questions/28242788/how-to-reset-custom-input-directive-and-its-parent-form-to-pristine but it seems quite dirty to me.

I would appreciate any ideas.

from angular-eonasdan-datetimepicker.

shustariov-andrey avatar shustariov-andrey commented on August 15, 2024

How about

if (ngModel.$viewValue === null) {
   ngModel.$setViewValue(null);
}

?

I mean, undefined value should not make model dirty at the first place

from angular-eonasdan-datetimepicker.

atais avatar atais commented on August 15, 2024

I should start putting comments in that code 😢

the reason i check for !ngModel.$viewValue instead of ngModel.$viewValue === null is that if you pass undefined or false to ng-model it would pass this value to the datetimepicker.

And actually eonasdan-datetimepicker does not like that and it causes console errors. The only value it accept is moment or null (I think Date was good too).

I have actually done the above in previous version 😉


What is more I think that it is not that ngModel.$setViewValue(null); causes $dirty state, but ngModel.$setViewValue(moment(ngModel.$viewValue)); in general ?

And this is basically linking the model to date time picker.

from angular-eonasdan-datetimepicker.

shustariov-andrey avatar shustariov-andrey commented on August 15, 2024

Ok, need to debug it deeper in this case...

from angular-eonasdan-datetimepicker.

shustariov-andrey avatar shustariov-andrey commented on August 15, 2024

ok, here what works fine for me now:

            if (!_.isUndefined(ngModel.$viewValue) && !moment.isMoment(ngModel.$viewValue)) {
                ngModel.$setViewValue(moment(ngModel.$viewValue));
            }
            if (moment.isMoment(ngModel.$viewValue)) {
                dpElement.data('DateTimePicker').date(ngModel.$viewValue);
            }

from angular-eonasdan-datetimepicker.

atais avatar atais commented on August 15, 2024

@shustariov-andrey would you fork the repo and make a PR?

I will test it and we can make a new version 👍 ?

from angular-eonasdan-datetimepicker.

shustariov-andrey avatar shustariov-andrey commented on August 15, 2024

ok, will do

from angular-eonasdan-datetimepicker.

atais avatar atais commented on August 15, 2024

Great! #21 fixed it.

Enjoy 0.3.9 available on bower & npm 😄 !

from angular-eonasdan-datetimepicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.