@ajaxjs/ui 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/dist/index.d.ts +10 -0
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/widget/HtmlEditor/HtmlEditor.vue +2 -2
- package/dist/widget/calendar/Calendar.d.ts +4 -4
- package/dist/widget/calendar/Calendar.js +7 -7
- package/dist/widget/calendar/Calendar.js.map +1 -1
- package/dist/widget/calendar/Calendar.less +3 -1
- package/dist/widget/calendar/Calendar.ts +8 -8
- package/dist/widget/calendar/Calendar.vue +2 -2
- package/dist/widget/form/validator.d.ts +63 -65
- package/dist/widget/form/validator.js +176 -178
- package/dist/widget/form/validator.js.map +1 -1
- package/dist/widget/form/validator.ts +216 -217
- package/package.json +11 -5
- package/dist/css/app.11ca79dd.css +0 -1
- package/dist/index.html +0 -1
- package/dist/js/app.44da9bce.js +0 -2
- package/dist/js/app.44da9bce.js.map +0 -1
- package/dist/js/chunk-vendors.0d9e9c3a.js +0 -8
- package/dist/js/chunk-vendors.0d9e9c3a.js.map +0 -1
|
@@ -1,215 +1,213 @@
|
|
|
1
|
-
|
|
2
|
-
(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return;
|
|
27
|
-
let result = Validator.check(el);
|
|
28
|
-
if (result) { // 如果有错误,就把它显示出来
|
|
29
|
-
this.errorElements.push(result);
|
|
30
|
-
this.showError(result);
|
|
31
|
-
}
|
|
32
|
-
else
|
|
33
|
-
this.removeError(el); // 否则, 移除所有存在的错误信息
|
|
34
|
-
}, true);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
* @param err
|
|
40
|
-
*/
|
|
41
|
-
showError(err) {
|
|
42
|
-
var _a;
|
|
43
|
-
let el = err.el, id = el.id || el.name; // 获取字段 id 或者 name
|
|
44
|
-
if (!id)
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Validator = void 0;
|
|
4
|
+
if (!('validity' in document.createElement('input')))
|
|
5
|
+
window.alert("不支持 HTML5 表单验证");
|
|
6
|
+
/**
|
|
7
|
+
* 表单验证器
|
|
8
|
+
*/
|
|
9
|
+
class Validator {
|
|
10
|
+
constructor(el) {
|
|
11
|
+
this.errorElements = [];
|
|
12
|
+
// let isMsgNewLine: boolean = el.dataset.msgNewline === "true";
|
|
13
|
+
el.setAttribute('novalidate', 'true'); // 禁止浏览器原生的错误提示
|
|
14
|
+
this.el = el;
|
|
15
|
+
this.checkEveryField();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 对每一个表单元素监听事件,一失去焦点就触发表单验证
|
|
19
|
+
*/
|
|
20
|
+
checkEveryField() {
|
|
21
|
+
let arr = this.el.querySelectorAll('input');
|
|
22
|
+
arr.forEach((input) => {
|
|
23
|
+
input.addEventListener('blur', (ev) => {
|
|
24
|
+
let el = ev.target;
|
|
25
|
+
if (el.tagName == "A" || Validator.isIgnoreEl(el)) // 忽略部分元素;a 元素也有 blur 事件,忽略之
|
|
45
26
|
return;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
message = document.createElement('div');
|
|
51
|
-
message.className = 'error-message';
|
|
52
|
-
message.id = 'error-for-' + id;
|
|
53
|
-
(_a = el.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(message, el.nextSibling);
|
|
54
|
-
}
|
|
55
|
-
el.setAttribute('aria-describedby', 'error-for-' + id); // 添加 ARIA role 到字段
|
|
56
|
-
message.innerHTML = err.msg; // 更新错误信息
|
|
57
|
-
// if (!isNewLine)// 显示错误信息
|
|
58
|
-
// message.style.display = 'inline-block';
|
|
59
|
-
message.classList.remove('hide');
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* 移除所有的错误信息
|
|
63
|
-
*
|
|
64
|
-
* @param el
|
|
65
|
-
*/
|
|
66
|
-
removeError(el) {
|
|
67
|
-
let id = el.id || el.name; // 获取字段的 id 或者 name
|
|
68
|
-
if (!id)
|
|
69
|
-
return;
|
|
70
|
-
el.classList.remove('error'); // 删除字段的错误类
|
|
71
|
-
el.removeAttribute('aria-describedby'); // 移除字段的 ARIA role
|
|
72
|
-
let message = el.form.$(`.error-message#error-for-${id}`); // 检查 DOM 中是否有错误消息
|
|
73
|
-
if (message) {
|
|
74
|
-
message.innerHTML = ''; // 如果有错误消息就隐藏它
|
|
75
|
-
message.classList.add('hide');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* 是否忽略的表单元素
|
|
80
|
-
*
|
|
81
|
-
* @param el
|
|
82
|
-
*/
|
|
83
|
-
static isIgnoreEl(el) {
|
|
84
|
-
return el.disabled || el.type === 'file' || el.type === 'reset' || el.type === 'submit' || el.type === 'button';
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* 验证字段
|
|
88
|
-
*
|
|
89
|
-
* @param field 表单字段元素
|
|
90
|
-
* @returns 若验证通过返回 null,否则返回 ErrorElement
|
|
91
|
-
*/
|
|
92
|
-
static check(field) {
|
|
93
|
-
// if (!field || !field.getAttribute)
|
|
94
|
-
// console.log(field);
|
|
95
|
-
let validity = field.validity; // 获取 validity
|
|
96
|
-
if (!validity)
|
|
97
|
-
throw '浏览器不支持 HTML5 表单验证';
|
|
98
|
-
if (validity.valid) // 通过验证
|
|
99
|
-
return null;
|
|
100
|
-
else {
|
|
101
|
-
let result = {
|
|
102
|
-
el: field,
|
|
103
|
-
msg: "无效输入" // 通用错误讯息 The value you entered for this field is invalid.
|
|
104
|
-
};
|
|
105
|
-
if (validity.valueMissing) // 如果是必填字段但是字段为空时
|
|
106
|
-
result.msg = '该项是必填项';
|
|
107
|
-
if (validity.typeMismatch) { // 如果类型不正确
|
|
108
|
-
if (field.type === 'email')
|
|
109
|
-
result.msg = '请输入有效的邮件地址';
|
|
110
|
-
else if (field.type === 'url')
|
|
111
|
-
result.msg = '请输入一个有效的网址';
|
|
112
|
-
else
|
|
113
|
-
result.msg = '请输入正确的类型';
|
|
114
|
-
}
|
|
115
|
-
if (validity.tooShort)
|
|
116
|
-
result.msg = `请输入至少${field.getAttribute('minLength')}个字符。当前你输入了${field.value.length}个字符。`;
|
|
117
|
-
// 'Please lengthen this text to ' + field.getAttribute('minLength') + ' characters or more. You are currently using ' + field.value.length + ' characters.'
|
|
118
|
-
if (validity.tooLong)
|
|
119
|
-
result.msg = `你只能输入最多${field.getAttribute('maxLength')}个字符。当前你输入了${field.value.length}个字符。`;
|
|
120
|
-
// 'Please shorten this text to no more than ' + field.getAttribute('maxLength') + ' characters. You are currently using ' + field.value.length + ' characters.';
|
|
121
|
-
if (validity.badInput)
|
|
122
|
-
result.msg = '请输入数字';
|
|
123
|
-
if (validity.stepMismatch) // 如果数字值与步进间隔不匹配
|
|
124
|
-
result.msg = '请选择一个有效值';
|
|
125
|
-
if (validity.rangeOverflow) // 如果数字字段的值大于 max 的值
|
|
126
|
-
result.msg = `请选择小于 ${field.getAttribute('max')} 的值`;
|
|
127
|
-
// return 'Please select a value that is no more than ' + field.getAttribute('max') + '.';
|
|
128
|
-
if (validity.rangeUnderflow)
|
|
129
|
-
result.msg = `请选择大于 ${field.getAttribute('min')} 的值`;
|
|
130
|
-
// return 'Please select a value that is no less than ' + field.getAttribute('min') + '.';
|
|
131
|
-
if (validity.patternMismatch)
|
|
132
|
-
result.msg = field.getAttribute('title') || '格式要求不正确';
|
|
133
|
-
return result;
|
|
27
|
+
let result = Validator.check(el);
|
|
28
|
+
if (result) { // 如果有错误,就把它显示出来
|
|
29
|
+
this.errorElements.push(result);
|
|
30
|
+
this.showError(result);
|
|
134
31
|
}
|
|
32
|
+
else
|
|
33
|
+
this.removeError(el); // 否则, 移除所有存在的错误信息
|
|
34
|
+
}, true);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param err
|
|
40
|
+
*/
|
|
41
|
+
showError(err) {
|
|
42
|
+
var _a;
|
|
43
|
+
let el = err.el, id = el.id || el.name; // 获取字段 id 或者 name
|
|
44
|
+
if (!id)
|
|
45
|
+
return;
|
|
46
|
+
err.el.classList.add('error'); // 将错误类添加到字段
|
|
47
|
+
// 检查错误消息字段是否已经存在 如果没有, 就创建一个
|
|
48
|
+
let message = err.el.form.querySelector(`.error-message#error-for-${id}`);
|
|
49
|
+
if (!message) {
|
|
50
|
+
message = document.createElement('div');
|
|
51
|
+
message.className = 'error-message';
|
|
52
|
+
message.id = 'error-for-' + id;
|
|
53
|
+
(_a = el.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(message, el.nextSibling);
|
|
54
|
+
}
|
|
55
|
+
el.setAttribute('aria-describedby', 'error-for-' + id); // 添加 ARIA role 到字段
|
|
56
|
+
message.innerHTML = err.msg; // 更新错误信息
|
|
57
|
+
// if (!isNewLine)// 显示错误信息
|
|
58
|
+
// message.style.display = 'inline-block';
|
|
59
|
+
message.classList.remove('hide');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 移除所有的错误信息
|
|
63
|
+
*
|
|
64
|
+
* @param el
|
|
65
|
+
*/
|
|
66
|
+
removeError(el) {
|
|
67
|
+
let id = el.id || el.name; // 获取字段的 id 或者 name
|
|
68
|
+
if (!id)
|
|
69
|
+
return;
|
|
70
|
+
el.classList.remove('error'); // 删除字段的错误类
|
|
71
|
+
el.removeAttribute('aria-describedby'); // 移除字段的 ARIA role
|
|
72
|
+
let message = el.form.querySelector(`.error-message#error-for-${id}`); // 检查 DOM 中是否有错误消息
|
|
73
|
+
if (message) {
|
|
74
|
+
message.innerHTML = ''; // 如果有错误消息就隐藏它
|
|
75
|
+
message.classList.add('hide');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 是否忽略的表单元素
|
|
80
|
+
*
|
|
81
|
+
* @param el
|
|
82
|
+
*/
|
|
83
|
+
static isIgnoreEl(el) {
|
|
84
|
+
return el.disabled || el.type === 'file' || el.type === 'reset' || el.type === 'submit' || el.type === 'button';
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 验证字段
|
|
88
|
+
*
|
|
89
|
+
* @param field 表单字段元素
|
|
90
|
+
* @returns 若验证通过返回 null,否则返回 ErrorElement
|
|
91
|
+
*/
|
|
92
|
+
static check(field) {
|
|
93
|
+
// if (!field || !field.getAttribute)
|
|
94
|
+
// console.log(field);
|
|
95
|
+
let validity = field.validity; // 获取 validity
|
|
96
|
+
if (!validity)
|
|
97
|
+
throw '浏览器不支持 HTML5 表单验证';
|
|
98
|
+
if (validity.valid) // 通过验证
|
|
99
|
+
return null;
|
|
100
|
+
else {
|
|
101
|
+
let result = {
|
|
102
|
+
el: field,
|
|
103
|
+
msg: "无效输入" // 通用错误讯息 The value you entered for this field is invalid.
|
|
104
|
+
};
|
|
105
|
+
if (validity.valueMissing) // 如果是必填字段但是字段为空时
|
|
106
|
+
result.msg = '该项是必填项';
|
|
107
|
+
if (validity.typeMismatch) { // 如果类型不正确
|
|
108
|
+
if (field.type === 'email')
|
|
109
|
+
result.msg = '请输入有效的邮件地址';
|
|
110
|
+
else if (field.type === 'url')
|
|
111
|
+
result.msg = '请输入一个有效的网址';
|
|
112
|
+
else
|
|
113
|
+
result.msg = '请输入正确的类型';
|
|
135
114
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
115
|
+
if (validity.tooShort)
|
|
116
|
+
result.msg = `请输入至少${field.getAttribute('minLength')}个字符。当前你输入了${field.value.length}个字符。`;
|
|
117
|
+
// 'Please lengthen this text to ' + field.getAttribute('minLength') + ' characters or more. You are currently using ' + field.value.length + ' characters.'
|
|
118
|
+
if (validity.tooLong)
|
|
119
|
+
result.msg = `你只能输入最多${field.getAttribute('maxLength')}个字符。当前你输入了${field.value.length}个字符。`;
|
|
120
|
+
// 'Please shorten this text to no more than ' + field.getAttribute('maxLength') + ' characters. You are currently using ' + field.value.length + ' characters.';
|
|
121
|
+
if (validity.badInput)
|
|
122
|
+
result.msg = '请输入数字';
|
|
123
|
+
if (validity.stepMismatch) // 如果数字值与步进间隔不匹配
|
|
124
|
+
result.msg = '请选择一个有效值';
|
|
125
|
+
if (validity.rangeOverflow) // 如果数字字段的值大于 max 的值
|
|
126
|
+
result.msg = `请选择小于 ${field.getAttribute('max')} 的值`;
|
|
127
|
+
// return 'Please select a value that is no more than ' + field.getAttribute('max') + '.';
|
|
128
|
+
if (validity.rangeUnderflow)
|
|
129
|
+
result.msg = `请选择大于 ${field.getAttribute('min')} 的值`;
|
|
130
|
+
// return 'Please select a value that is no less than ' + field.getAttribute('min') + '.';
|
|
131
|
+
if (validity.patternMismatch)
|
|
132
|
+
result.msg = field.getAttribute('title') || '格式要求不正确';
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 是否通过验证
|
|
138
|
+
*
|
|
139
|
+
* @param form
|
|
140
|
+
*/
|
|
141
|
+
static onSubmit(form) {
|
|
142
|
+
let fields = form.elements; // 获取所有的表单元素
|
|
143
|
+
// 验证每一个字段
|
|
144
|
+
// 将具有错误的第一个字段存储到变量中以便稍后我们将其默认获得焦点
|
|
145
|
+
let error, hasErrors = null;
|
|
146
|
+
for (let i = 0, j = fields.length; i < j; i++) {
|
|
147
|
+
let el = fields[i];
|
|
148
|
+
error = this.check(el);
|
|
149
|
+
if (error) {
|
|
150
|
+
// showError(el);
|
|
151
|
+
if (!hasErrors) // 如果有错误,停止提交表单并使出现错误的第一个元素获得焦点
|
|
152
|
+
hasErrors = el;
|
|
160
153
|
}
|
|
161
154
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
155
|
+
if (hasErrors) {
|
|
156
|
+
hasErrors.focus();
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.Validator = Validator;
|
|
163
|
+
// ; (function (window, document, undefined) { // 确保 ValidityState 全部被支持 (所有的功能)
|
|
166
164
|
// var supported = function () {
|
|
167
165
|
// var input = document.createElement('input');
|
|
168
166
|
// return ('validity' in input && 'badInput' in input.validity && 'patternMismatch' in input.validity && 'rangeOverflow' in input.validity && 'rangeUnderflow' in input.validity && 'stepMismatch' in input.validity && 'tooLong' in input.validity && 'tooShort' in input.validity && 'typeMismatch' in input.validity && 'valid' in input.validity && 'valueMissing' in input.validity);
|
|
169
167
|
// };
|
|
170
|
-
// /**
|
|
168
|
+
// /**
|
|
171
169
|
// * Generate the field validity object
|
|
172
|
-
// * @param {Node]} field The field to validate
|
|
173
|
-
// * @return {Object} The validity object
|
|
170
|
+
// * @param {Node]} field The field to validate
|
|
171
|
+
// * @return {Object} The validity object
|
|
174
172
|
// **/
|
|
175
173
|
// var getValidityState = function (field) {
|
|
176
|
-
// // 变量
|
|
177
|
-
// var type = field.getAttribute('type') || input.nodeName.toLowerCase();
|
|
178
|
-
// var isNum = type === 'number' || type === 'range';
|
|
179
|
-
// var length = field.value.length; var valid = true;
|
|
174
|
+
// // 变量
|
|
175
|
+
// var type = field.getAttribute('type') || input.nodeName.toLowerCase();
|
|
176
|
+
// var isNum = type === 'number' || type === 'range';
|
|
177
|
+
// var length = field.value.length; var valid = true;
|
|
180
178
|
// //检测支持性
|
|
181
179
|
// var checkValidity = {
|
|
182
180
|
// badInput: (isNum && length > 0 && !/[-+]?[0-9]/.test(field.value)),
|
|
183
|
-
// // 数字字段的值不是数字
|
|
181
|
+
// // 数字字段的值不是数字
|
|
184
182
|
// patternMismatch: (field.hasAttribute('pattern') && length > 0 && new RegExp(field.getAttribute('pattern')).test(field.value) === false),
|
|
185
|
-
// // 输入的值不符合模式
|
|
183
|
+
// // 输入的值不符合模式
|
|
186
184
|
// rangeOverflow: (field.hasAttribute('max') && isNum && field.value > 1 && parseInt(field.value, 10) > parseInt(field.getAttribute('max'), 10)),
|
|
187
|
-
// // 数字字段的值大于max属性值
|
|
185
|
+
// // 数字字段的值大于max属性值
|
|
188
186
|
// rangeUnderflow: (field.hasAttribute('min') && isNum && field.value > 1 && parseInt(field.value, 10) < parseInt(field.getAttribute('min'), 10)),
|
|
189
187
|
// // 数字字段的值小于min属性值
|
|
190
188
|
// stepMismatch: (field.hasAttribute('step') && field.getAttribute('step') !== 'any' && isNum && Number(field.value) % parseFloat(field.getAttribute('step')) !== 0),
|
|
191
|
-
// // 数字字段的值不符合 stepattribute
|
|
189
|
+
// // 数字字段的值不符合 stepattribute
|
|
192
190
|
// tooLong: (field.hasAttribute('maxLength') && field.getAttribute('maxLength') > 0 && length > parseInt(field.getAttribute('maxLength'), 10)),
|
|
193
191
|
// // 用户在具有maxLength属性的字段中输入的值的长度大于属性值
|
|
194
192
|
// tooShort: (field.hasAttribute('minLength') && field.getAttribute('minLength') > 0 && length > 0 && length < parseInt(field.getAttribute('minLength'), 10)),
|
|
195
|
-
// // 用户在具有minLength属性的字段中输入的值的长度小于属性值
|
|
193
|
+
// // 用户在具有minLength属性的字段中输入的值的长度小于属性值
|
|
196
194
|
// typeMismatch: (length > 0 && ((type === 'email' && !/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/.test(field.value)) || (type === 'url' && !/^(?:(?:https?|HTTPS?|ftp|FTP):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)*)(?::\d{2,5})?(?:[\/?#]\S*)?$/.test(field.value)))),
|
|
197
|
-
// // email 或者 URL 字段的值不是一个 email地址或者 URL
|
|
198
|
-
// valueMissing: (field.hasAttribute('required') && (((type === 'checkbox' || type === 'radio') && !field.checked) || (type === 'select' && field.options[field.selectedIndex].value < 1) || (type !== 'checkbox' && type !== 'radio' && type !== 'select' && length < 1))) // 必填字段没有值
|
|
195
|
+
// // email 或者 URL 字段的值不是一个 email地址或者 URL
|
|
196
|
+
// valueMissing: (field.hasAttribute('required') && (((type === 'checkbox' || type === 'radio') && !field.checked) || (type === 'select' && field.options[field.selectedIndex].value < 1) || (type !== 'checkbox' && type !== 'radio' && type !== 'select' && length < 1))) // 必填字段没有值
|
|
199
197
|
// };
|
|
200
|
-
// // 检查是否有错误
|
|
198
|
+
// // 检查是否有错误
|
|
201
199
|
// for (var key in checkValidity) {
|
|
202
200
|
// if (checkValidity.hasOwnProperty(key)) {
|
|
203
|
-
// // If there's an error, change valid value
|
|
201
|
+
// // If there's an error, change valid value
|
|
204
202
|
// if (checkValidity[key]) { valid = false; break; }
|
|
205
203
|
// }
|
|
206
204
|
// }
|
|
207
205
|
// // 给 validity 对象添加 valid 属性
|
|
208
206
|
// checkValidity.valid = valid;
|
|
209
|
-
// // 返回对象
|
|
207
|
+
// // 返回对象
|
|
210
208
|
// return checkValidity;
|
|
211
209
|
// };
|
|
212
|
-
// // 如果不支持完整的 ValidityState 功能,则可以使用polyfill
|
|
210
|
+
// // 如果不支持完整的 ValidityState 功能,则可以使用polyfill
|
|
213
211
|
// if (!supported()) {
|
|
214
212
|
// Object.defineProperty(HTMLInputElement.prototype, 'validity', {
|
|
215
213
|
// get: function ValidityState() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../src/widget/form/validator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../src/widget/form/validator.ts"],"names":[],"mappings":";;;AA2BA,IAAI,CAAC,CAAC,UAAU,IAAI,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAEnC;;GAEG;AACH,MAAa,SAAS;IAClB,YAAY,EAAmB;QAYvB,kBAAa,GAAmB,EAAE,CAAC;QAXvC,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