Comments (10)
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.
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.
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.
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.
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.
Ok, need to debug it deeper in this case...
from angular-eonasdan-datetimepicker.
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.
@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.
ok, will do
from angular-eonasdan-datetimepicker.
Great! #21 fixed it.
Enjoy 0.3.9
available on bower & npm 😄 !
from angular-eonasdan-datetimepicker.
Related Issues (20)
- Does not set the value at all HOT 2
- How to disable triggering the picker on span click HOT 3
- Set time
- Deprecation warning: value provided is not in a recognized RFC2822 or ISO format HOT 2
- ngMessages not working with datetimepicker HOT 1
- Support for jQuery 3 in dependencies HOT 3
- Manually entered dates issues HOT 2
- How to configure global datetimepicker options like in diosney version HOT 2
- Cannot read property 'length' of undefined HOT 2
- i m use this datetime picker i face this issue . HOT 1
- Not Compatible with MomentJS 2.9+ HOT 1
- Problem when used in dynamically loaded templates HOT 1
- Inline doesn't stay open HOT 2
- How to close the datetimepicker after selection of time HOT 1
- Support for Angular 6 HOT 1
- Setting date-only value from controller makes datetimepicker to display one day before HOT 3
- Setting minDate in erasing default/initial value (AngularJS)
- ng-change triggers when picker is opened first time (just open not change) (AngularJS) HOT 1
- plnkr 's not working anymore HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-eonasdan-datetimepicker.