Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Format not applying in AngularJS #34

Closed
loganwedwards opened this issue Mar 5, 2015 · 7 comments
Closed

Data Format not applying in AngularJS #34

loganwedwards opened this issue Mar 5, 2015 · 7 comments

Comments

@loganwedwards
Copy link

I have the following:

<input id="dateStart" type="date" data-format="MM/dd/yyyy" value="2015-01-01" ng-model="..." />

I've also tried setting the value attribute in the JavaScript code using

// $scope.dateQuery.startInput looks like YYYY-MM-dd format
document.getElementById('dateStart').setAttribute('value',$scope.dateQuery.startInput);

At any rate, the formatting is not being applied and was curious if this has been noticed. Anything specific that I can provide? I was thinking about wrapping this datepicker in an Angular directive, but wanted to hold off if I'm doing something obviously wrong.

Thanks!

@chemerisuk
Copy link
Owner

@loganwedwards hi. I believe you just need to trigger change event manually after any change you make. Angular has $watch method, that you can probably use to solve that problem.

@chemerisuk
Copy link
Owner

@loganwedwards also, if you prefer do it manually, do not update attribute value use property instead:

document.getElementById('dateStart').value = $scope.dateQuery.startInput;

@debuggerpk
Copy link

@loganwedwards any update on this?

@loganwedwards
Copy link
Author

I apologize that this is way overdue, but after upgrading to 1.5.2, it seems the issue is resolved.

I don't need to trigger any special handlers, setup any watchers, etc... I may have had an old version of this library and or better-dom.

The syntax in the view is now simply:

<input type="date" id="dateStart" name="dateStart" data-format="MM/dd/yyyy" ng-model="dateQuery.start"  />

Sorry for the trouble! Keep up the great work.

@chemerisuk
Copy link
Owner

@loganwedwards do you have any idea what has changed in Angular 1.5.2? Does it trigger change events by itself after value was updated?

@loganwedwards
Copy link
Author

@chemerisuk Clarification, I upgraded better-dateinput-polyfill to 1.5.2.

@chemerisuk
Copy link
Owner

@loganwedwards ah, yes. alright, cool then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants