5

I am trying to use angular-ui-mask with angular-ui-bootstrap datepicker component.

When I use this, the input gets assigned with ng-invalid-date classes even though the date is valid date and date gets cleared after I focus out of the field.

I don't want to use HTML input with type='date' as it is not supported by all browsers.

plunker for the same:

http://plnkr.co/edit/dW4AIlF37CLbSHf553d3?p=preview

  <input type="text" class="form-control" ui-mask="99/99/9999" uib-datepicker-popup ng-model="dt" is-open="status.opened" min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />

Inspect element to see classes assigned to it.

1
  • @Anil Natha, Thanks for reformatting the question. Commented Oct 19, 2015 at 16:15

3 Answers 3

2

Luiz's answer was kinda right, but very unclear (if you want the slashes removed). Since by default ui-mask will strip out the placeholders, you need to send it to the uib-datepicker-popup without them by using: uib-datepicker-popup="MMddyyyy", e.g:

<input type="text" uib-datepicker-popup="MMddyyyy" ui-mask="99/99/9999" ... >

Alternatively, if you want to keep the placeholder (slashes) you can set model-view-value="true", e.g:

<input type="text" uib-datepicker-popup="MM/dd/yyyy" ui-mask="99/99/9999" model-view-value="true" ... >
Sign up to request clarification or add additional context in comments.

Comments

0

I don't understand why you want to use the mask

you need to use the option datepicker-popup and provide your formatting in it

datepicker-popup="MM/dd/yyyy"

1 Comment

datepicker-popup provides formatting when user selects date from datepicker control. My requirement is to apply formatting(masking) when user types in the date manually instead of selecting from datepicker.
0

The ui-mask don't send to backend the fillings, so to use it you will need to do like this:

 <input type="text" class="form-control" ui-mask="99/99/9999" uib-datepicker-popup="ddMMyyyy" ng-model="dt" is-open="status.opened" min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.