Closed Incognito-Nemo closed 9 years ago
Just to be sure. are you loading the fr
locally from momentjs
? Some thing like:
<script type="text/javascript" src="bower_components/moment/locale/fr.js"></script>
I tested the examples.html in the repo with your settings and worked for me.
Can you set a jsfiddle with the issue for me to check it? (I can't access plunkr due some restrictions).
yes the moment locale fr file is correctly loaded. The problem apears when I do the data binding. Without it, your directive works fine!
The only think I can think of now is that ngModel is setting an initial value with a format that .datetimepicker()
can't parse, so it leaves as it is.
Try to set personne.pDateNaissance
in a valid format to check if it is that, something like:
$scope.personne = {
pDateNaissance: '22/03/2015'
}
Besides, these are some actions you can take to help me to find the issue:
There are no errors in the browser's Dev Tools and I receive the date with json in the format ""1973-02-22T00:00:00.000" that is ISO 8601.
In the solution https://gist.github.com/eugenekgn/f00c4d764430642dca4b there are :
/// returns moments.js format object scope.dateTime = new Date(elem.data("DateTimePicker").getDate().format()); // Global change propagation $rootScope.$broadcast("emit:dateTimePicker", { location: scope.location, action: 'changed', dateTime: scope.dateTime, example: scope.useCurrent }); scope.$apply();/
It is not missing in your solution ?
(sorry but I begin with angular !)
No, that code is not needed at all.
About your issue, it seems that we were talking about two different things, locale
and format
.
Locale is for UI internacionalization, so the question here is: do you see the datetimepicker UI in french?
About the format issue, it seems that I will need a working page to being able to trace the issue, can you set up one so I can check it?
Yes I have Datetime picker in french. I hope having the time to make a fiddle page tomorrow (I never do it...)
Good night!
Ok, I will leave the issue opened then, waiting for the fiddle.
GN to you
Hello !
I understand a little more my problem : the date is not a string but a Date javascript object as you can see at http://almageste.info/tests/datetimepicker
I redefined the link part as : link: function ($scope, $element, $attrs, ngModelCtrl) { var passed_in_options = $scope.$eval($attrs.datetimepickerOptions); var options = jQuery.extend({}, default_options, passed_in_options);
var format = passed_in_options.format;
// When data changes inside AngularJs, notify the third party directive of the change
ngModelCtrl.$render = function () {
$element.val(moment(ngModelCtrl.$viewValue).format(format).toString());
};
// When data changes outside of AngularJs
$element
.on('dp.change', function (on_change_event) {
if (ngModelCtrl) {
$timeout(function () {
ngModelCtrl.$setViewValue(moment(on_change_event.target.value, format).toDate());
});
}
})
.datetimepicker(options);
}
What do you think about this?
Sorry for the delay, I was very busy with other projects.
On this, I prefer to let the string formatting outside the directive scope, and let the controller to do it to make the directive simple and similar to the original one, so I will close the issue to wait for more users to give their opinion.
Hello ! it seems that locale doesn't work for me… I use french date format with DD/MM/YYYY (and not the english format MM/DD/YYYY) and when I select a date (for example 10/04/2015 in french format) in the picker, the input show Sun Oct 04 2015 00:00:00 GMT+0200. It should show '10/04/2015'...
I use this script : <input type="text" class="form-control" datetimepicker datetimepicker-options="{ format: 'DD/MM/YYYY', locale: 'fr', icons:{ next:'glyphicon glyphicon-arrow-right', previous:'glyphicon glyphicon-arrow-left', up:'glyphicon glyphicon-arrow-up', down:'glyphicon glyphicon-arrow-down'} }" placeholder="JJ/MM/AAAA" ng-model="personne.pDateNaissance">
Any idea ?