angular-datepicker icon indicating copy to clipboard operation
angular-datepicker copied to clipboard

Change datetime field and get the changed value

Open yelnar opened this issue 10 years ago • 8 comments

I have an input field with datetime picker, bad when I pick the datetime everything is ok, but when I change this vaue in input field(not in template) the data doesn't change.

yelnar avatar Dec 10 '14 13:12 yelnar

I have the same problem..

mortenholmgaard avatar Jan 09 '15 09:01 mortenholmgaard

I have found a way to fix this:

In Module.directive('dateTime' ...) link method: element.bind("change", function (e) { //Custom method console.log("Input changed"); var newDate = parseDate(e.srcElement.value, e.srcElement.attributes["format"].value); scope.$broadcast('set-user-typed-date', { date: newDate }); clear(); });

This code to parse any date format: function parseDate(input, format) { // http://karpcom.blogspot.dk/2011/02/constructing-javascript-date-object.html format = format || 'dd/MM/yyyy'; // somedefault format var parts = input.match(/(\d+)/g), i = 0, fmt = {}; // extract date-part indexes from the format format.replace(/(yyyy|dd|MM)/g, function (part) { fmt[part] = i++; }); return new Date(parts[fmt['yyyy']], parts[fmt['MM']] - 1, parts[fmt['dd']]); }

And this in Module.directive('datePicker' ...) link method: scope.$on('set-user-typed-date', function (event, args) {//Custom code scope.setDate(args.date); });

mortenholmgaard avatar Jan 09 '15 11:01 mortenholmgaard

set the value with "new Date()" not a String

dam1 avatar Jan 25 '15 21:01 dam1

I have tried mortenholmgaard's method, but on the ngModel, only the view value is changed, the modelValue is still not changed :(

flyawaychen avatar Apr 12 '15 20:04 flyawaychen

flyawaychen send a plunker with example code please.

eralha avatar Apr 13 '15 08:04 eralha

@yelnar +1 http://plnkr.co/edit/JEe8jb?p=preview

When I insert/change date by input (using keyboard) ng-model value is not updated.

rjurado01 avatar Jul 27 '15 07:07 rjurado01

@rjurado01 i changed this: parseDate(e.srcElement.value, e.srcElement.attributes["format"].value); to this: parseDate(e.originalEvent.srcElement.value, e.originalEvent.srcElement.attributes["format"].value);

and finally i do this:

var format = "yyyy-MM-dd"; var newDate = parseDate(e.originalEvent.srcElement.value, format);

and i have to do this:

scope.$apply();

SimonKlausLudwig avatar Aug 12 '15 12:08 SimonKlausLudwig

This is very annoying , when editing the fields. @mortenholmgaard thanks for fix.

knvpk avatar Jan 10 '16 07:01 knvpk