2015-10-19 85 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" ... >