Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Datepicker doesn't work with ng-model-options="{ allowInvalid: true }" #4694

Closed
distinctdan opened this issue Oct 22, 2015 · 5 comments
Closed

Comments

@distinctdan
Copy link

I'm trying to get the datepicker's input to set the model value even if the user entered invalid stuff, but it doesn't appear to respect ng-model-options' allowInvalid parameter.

@distinctdan
Copy link
Author

After some thought, I think what I'm really looking is for an option to make the datepicker's validation a bit looser, specifically, to allow leading 0's. The whole reason I was trying to disable validation is because the datepicker errors if the format isn't exactly right, so if the user enters "7/09/2015", it'll error if my format is "M/d/yyyy". Even though the datepicker should still output the desired format, it would be nice if there was an option to allow leading 0's in the input.

For now, I've modified the regexs in dateParser to accept leading 0's for days and months. I don't like modifying a library because it means extra effort when you upgrade, but I really don't see any other option since there's no way to extend/modify the date parsing. After looking at the code, I'm starting to see that disabling validation isn't that useful, since the datepicker sets the model value to be a date object, and if it can't parse the date, it still can't output anything.

I see that the date parser uses a big object of formats, with a regex for each format. What if we exposed this object, so that external code could override the formats?

@icfantv
Copy link
Contributor

icfantv commented Oct 23, 2015

I think this may be a duplicate of #2906.

@wesleycho wesleycho added this to the 1.0.0 milestone Oct 31, 2015
@wesleycho
Copy link
Contributor

We added dateparser support for optional leading zeroes, but it would be nice to add support for all ngModelOptions config

@wesleycho
Copy link
Contributor

Closing in favor of #4837

wesleycho pushed a commit that referenced this issue Dec 10, 2015
- Adds support for invalid view values via `ngModelOptions`
  allowInvalid` setting

Closes #4694
Closes #4837
@dadoadk
Copy link

dadoadk commented Feb 10, 2016

I'm still having issues with this. I'm on version 1.1.2 angular-bootstrap, and have a uib-datepicker-popup="MM-dd-yyyy" with ng-model-options="{allowInvalid:true}". So my form requires users to enter dash "-" if they don't know the date. Everything is fine when they enter the dash, datepicker still opens on click if they want to change it to a date, form saves. Now, when form is loaded, ng-model takes the value of "-" dash and doesn't display it in input text box, also when user clicks on datepicker an error pops up with exception: "TypeError: this.activeDate.getFullYear is not a function at _refreshView"

Can you help me out with this issue? seems like on load the datepicker doesn't take "-" dash value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants