eight04 / angular-datetime

A directive to add the behavior of datetime input on unsupported browsers.
MIT License
93 stars 28 forks source link

Empty value results in (year).(month)... #39

Closed domschmidt closed 7 years ago

domschmidt commented 8 years ago

Hey there,

I really like this library

Starting with version 4.0.0, if the input field value is empty, the field value is something like

image

This behaviour is really strange. Could you please re-check this decision in 4.0.0 again?

Furthermore, in 4.1.0, even if required/ng-required is set to false, after selecting a date and removing it, the form becomes invalid as the current value (empty) cannot be parsed as a date.

eight04 commented 8 years ago

Here is the original thread

Before version 4.0.0, the value become empty string when the model is null. And here is the behavior what we had:

Current:

Any better idea? I tend to use second solution and try to indicate the format in placeholder attr. Or just always add required attr and use a checkbox to decide whether to use that input field.

current value (empty) cannot be parsed as a date

Confirmed. It will be fixed soon.

JanBrinker commented 8 years ago

Hi there, I'm basically having the same issue. I'd also vote for displaying the placeholder until the user tries to enter something. Or alternatively offer an option of defining how the format should look like. That would help localization of websites with your module :)

eight04 commented 8 years ago

Like this?

<input ... datetime-placeholder="localizedPlacehold">
$scope.localizedPlacehold = {
    "year": "...",
    "month": "...",
    ...
};

@domschmidt Another problem is the behavior when pressing delete/backspace:

  1. Remove all text in the input. element.val("")
  2. Use a placeholder to replace deleted part just like current behavior.
  3. Others... ?
domschmidt commented 8 years ago

The proposed solution would be perfect! A localized placeholder variant would be great and would mean that we can migrate to 4.x :-)

Regarding the backspace button: I'd vote for a "natural" feeling:

initial case: (year)-(month)-(day)

the user enters a date 2016-10-04 presses backspace 2016-10-0_ (underscore marks the current cursor) and again 2016-10-_ and again 2016-1_-(day)

and finally, when all parts are removed, the full localized placeholder is shown again.

If the user clicks on the month, then the entered month value is highlighted (marked). If the user uses backspace, then the marked area is deleted and the cursor is on the month area.

initial case: 2016-10-04 the user clicks on the month, then the month is highlighted: 2016-*10*-04 (* surrounds the highlighted area) If the user presses backspace, the month is removed and the cursor is set to the month area: 2016-_-04 (underscore marks the current cursor) On pressing backspace again, the year is cut and the cursor is on the last part of the year: 201_-(month)-04

JanBrinker commented 8 years ago

Sounds good :) Alternatively the definition of the placeholders could also happen in an initialization step during config. But both ways seem good to me :)

eight04 commented 8 years ago

https://github.com/eight04/angular-datetime/tree/dev-placeholder http://liveweave.com/lmzSFr ng-trim is required for those formats containing spaces.

eight04 commented 7 years ago

Added at v5.0.0.

Configure it like this:

angular
    .module("myApp", ["datetime"])
    .config(function(datetimePlaceholder){
        angular.extend(datetimePlaceholder, {
            year: "<placeholder for year>",
            month: "<placeholder for month>",
            date: "<placeholder for date>"
        });
    });

For all valid keys see https://github.com/eight04/angular-datetime#datetimeplaceholder-object

eight04 commented 7 years ago

Do you mean to reset the date on focus event? Try to reset the date with ng-focus directive.