angular-bootstrap-datetimepicker-directive icon indicating copy to clipboard operation
angular-bootstrap-datetimepicker-directive copied to clipboard

Locale fr

Open Incognito-Nemo opened this issue 11 years ago • 10 comments

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 :

Any idea ?

Incognito-Nemo avatar Mar 22 '15 10:03 Incognito-Nemo

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).

diosney avatar Mar 22 '15 15:03 diosney

yes the moment locale fr file is correctly loaded. The problem apears when I do the data binding. Without it, your directive works fine!

Incognito-Nemo avatar Mar 22 '15 16:03 Incognito-Nemo

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:

  • See if there are any erros thrown in the browser's Dev Tools,
  • Set a jsfiddle showcasing the issue.

diosney avatar Mar 22 '15 16:03 diosney

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 !)

Incognito-Nemo avatar Mar 22 '15 18:03 Incognito-Nemo

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?

diosney avatar Mar 22 '15 18:03 diosney

Yes I have Datetime picker in french. I hope having the time to make a fiddle page tomorrow (I never do it...)

Good night!

Incognito-Nemo avatar Mar 22 '15 19:03 Incognito-Nemo

Ok, I will leave the issue opened then, waiting for the fiddle.

GN to you

diosney avatar Mar 22 '15 19:03 diosney

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

Incognito-Nemo avatar Mar 23 '15 16:03 Incognito-Nemo

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?

Incognito-Nemo avatar Mar 23 '15 17:03 Incognito-Nemo

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.

diosney avatar Apr 28 '15 14:04 diosney