?
? ????? PHP ??? ???? ??? ?? ??
年的周數(shù)輸入的驗(yàn)證和轉(zhuǎn)換到日期。目前的瀏覽器還不支持HTML5的周輸入控件,所以將使用文本輸入。 在這種情況下,輸入的文本必須符合ISO-8601的日期格式(yyyy-W##)的校驗(yàn)規(guī)范,例如:2013-W02
。模型必須永遠(yuǎn)是一個(gè)Date對象。
<input Type="week"
ng-model=""
[name=""]
[min=""]
[max=""]
[required=""]
[ng-required=""]
[ng-change=""]>
參數(shù) | 類型 | 詳述 |
---|---|---|
ngModel | string | 聲明用于數(shù)據(jù)綁定的Angular表達(dá)式。 |
name (可選)
|
string | 發(fā)布到表單下的控件的屬性名稱。 |
min
(可選)
|
string | 當(dāng)輸入的值小于 |
max
(可選)
|
string | 當(dāng)輸入的值大于 |
required
(可選)
|
string | 如果未輸入值就設(shè)置 |
ngRequired
(可選)
|
string | 當(dāng)ngRequired表達(dá)式等于true時(shí),添加 |
ngChange
(可選)
|
string | Angular表達(dá)式,當(dāng)輸入元素通過用戶交互方式發(fā)生輸入變化時(shí)會(huì)執(zhí)行這個(gè)表達(dá)式。 |
<script>
angular.module('weekExample', [])
.controller('DateController', ['$scope', Function($scope) {
$scope.value = new Date(2013, 0, 3);
}]);
</script>
<form name="myForm" ng-controller="DateController as dateCtrl">
Pick a date between in 2013:
<input id="exampleInput" Type="week" name="input" ng-model="value"
placeholder="YYYY-W##" min="2012-W32" max="2013-W52" required />
<span class="error" ng-show="myForm.input.$error.required">
Required!</span>
<span class="error" ng-show="myForm.input.$error.week">
Not a valid date!</span>
<tt>value = {{value | date: "yyyy-Www"}}</tt><br/>
<tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br/>
<tt>myForm.input.$error = {{myForm.input.$error}}</tt><br/>
<tt>myForm.$valid = {{myForm.$valid}}</tt><br/>
<tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/>
</form>
protractor.js
var value = element(by.binding('value | date: "yyyy-Www"'));
var valid = element(by.binding('myForm.input.$valid'));
var input = element(by.model('value'));
// currently protractor/webdriver does not support
// sending keys to all known HTML5 input controls
// for various browsers (https://github.com/angular/protractor/issues/562).
Function setInput(val) {
// set the value of the element and force validation.
var scr = "var ipt = document.getElementById('exampleInput'); " +
"ipt.value = '" + val + "';" +
"angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });";
browser.executeScript(scr);}
it('should initialize to model', Function() {
expect(value.getText()).toContain('2013-W01');
expect(valid.getText()).toContain('myForm.input.$valid = true');});
it('should be invalid if empty', Function() {
setInput('');
expect(value.getText()).toEqual('value =');
expect(valid.getText()).toContain('myForm.input.$valid = false');});
it('should be invalid if over max', Function() {
setInput('2015-W01');
expect(value.getText()).toContain('');
expect(valid.getText()).toContain('myForm.input.$valid = false');});