2015-10-19 136 views
4

我正在尝试使用angular-ui-mask与角度ui-bootstrap datepicker组件。角度ui面具不与角-ui datepicker

当我使用这个时,即使日期有效,日期和日期在我离开字段后被清除,输入也会被赋予ng-invalid-date类。

我不想在type='date'中使用HTML输入,因为它不被所有浏览器支持。

plunker对于相同:

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" /> 

检查元件看分配给它的类。

+0

@Anil Natha,感谢您对问题的重新格式化。 – Sreekanth

回答

0

我不明白你为什么要使用口罩

您需要使用的选项datepicker-popup和它

datepicker-popup="MM/dd/yyyy" 
+1

datepicker-popup在用户从datepicker控件选择日期时提供格式。我的要求是当用户手动键入日期而不是从日期选择器中选择时,应用格式(屏蔽)。 – Sreekanth

0

ui的面罩提供您的格式不发送到后端馅料,所以使用它,你需要做的是这样的:

<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" /> 
1

路易斯的回答是有点权,但非常不清晰(如果你想删除的斜线)。由于默认UI的面具将剥离出的占位符,您需要使用到其发送到UIB-日期选择器,弹出没有他们:uib-datepicker-popup="MMddyyyy",如:

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

另外,如果你想保留的占位符(斜线)你可以设置model-view-value="true",例如:

<input type="text" uib-datepicker-popup="MM/dd/yyyy" ui-mask="99/99/9999" model-view-value="true" ... >