bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Datepicker - disable validation option

Open Blackbaud-PatrickOFriel opened this issue 11 years ago • 9 comments

I have a situation where in some cases where I am using the datepicker popup and I don't want the manually entered input to go through the datepicker's validation (I want to do custom validation instead). Are there any plans to have either an option to disable validation on the datepicker or an option to provide custom validation for the datepicker (or maybe there's already a way that I'm too thick to discover today)? Thanks for all your work!

Blackbaud-PatrickOFriel avatar Jun 18 '15 14:06 Blackbaud-PatrickOFriel

I am currently in the process of working on a fix to the validation of the datepicker component here - once this is implemented, one can write a custom directive with a $timeout hack to overwrite ngModelCtrl.$validators, allowing for custom validators.

wesleycho avatar Jun 27 '15 04:06 wesleycho

I found a way to hack around the current validation (albeit in a very strange way), my main pain point at the moment is this guy popping up angry and red in the console when I'm doing my own validation: $log.error('Datepicker directive: "ng-model" value must be a Date object, a number of milliseconds since 01.01.1970 or a string representing an RFC2822 or ISO 8601 date.');. Any way this can be a warning instead of an error?

Blackbaud-PatrickOFriel avatar Jun 28 '15 21:06 Blackbaud-PatrickOFriel

Any more info on whether we can have that $log.error be a warning, or better yet, not exist? I've managed to hack my own validation, but that console error keeps coming up.

Blackbaud-PatrickOFriel avatar Jul 30 '15 14:07 Blackbaud-PatrickOFriel

One can disable $log via

$provide.factory('$log', function() {
  return {
    debug: angular.noop,
    error: angular.noop,
    log: angular.noop,
    warn: angular.noop
  };
});

wesleycho avatar Aug 04 '15 02:08 wesleycho

I thought about doing that, but I really only wanted to disable the validation for this case, since I know that I'm overriding the typical validation here. I dont want to suppress all log messages in my application. I'll try to think of another way to work around it.

Blackbaud-PatrickOFriel avatar Aug 04 '15 13:08 Blackbaud-PatrickOFriel

One way is to file a PR that creates an injectable $datepickerSuppressError and $dateparserSuppressWarning and the $log usage in those components can then check for the truth condition. similar to how it is done in $transition.

wesleycho avatar Aug 04 '15 14:08 wesleycho

Okay I'll take a look at that, thanks!

Blackbaud-PatrickOFriel avatar Aug 04 '15 14:08 Blackbaud-PatrickOFriel

I too, am in need of disabling the validation. I set the entered value to the api on the model, even if the user has entered stuff that doesn't exactly match the format, like leading 0's for the day and month. Could we add a disable-validation attribute that turns off the datepicker's validation to allow setting invalid values?

Note that I've tried ng-model-options="{ allowInvalid: true }", but it doesn't have any effect.

distinctdan avatar Oct 22 '15 21:10 distinctdan

It would be a great thing if this would be implemented. I for example is using using this datepicker as a filter header in ui-grid. If a user then wants to only write 2014, then the filtering won't work as 2014 is not a valid date.

mathiasdose avatar Dec 01 '15 14:12 mathiasdose