2

I'm trying to implement a feature for a form where:
1. I display a date string in the format mm-dd-yyyy
2. User is allowed to edit the form, and the date string would remain in the format mm-dd-yyyy
3. When the user submits the form, the date string must be in the format yyyy-mm-dd.
3. The original format of the date string is yyyy-mm-dd.

I would prefer to achieve this somehow by means of a directive rather than calling a function everytime a user submits a form, was wondering if there were any thoughts on a good way to do this?

I've given angular-ui-mask a look but am not sure if this would help me so much for this case.

Thanks!

vlin
  • 825
  • 1
  • 6
  • 13
  • you can also do it in the submit method – Milan Dec 15 '15 at 21:44
  • Limitation here is that I'm using this form in many views, and would prefer to not do re-formatting on the submit method in each view – vlin Dec 15 '15 at 21:45
  • you would be reformatting 'incorrect' data before processing. you can in the submit method check if your date is in incorrect format and fix it before processing (e.g. trying to store the value) – Milan Dec 15 '15 at 21:49
  • 1
    Use formatters and parsers? http://stackoverflow.com/questions/22841225/ngmodel-formatters-and-parsers – stephen.vakil Dec 15 '15 at 21:50

0 Answers0