1 |
|
2 | # 验证设置Validate
|
3 |
|
4 | 创建dataTable,field字段中验证字段,基本设置如下:
|
5 |
|
6 | new u.DataTable({
|
7 | meta:{
|
8 | field:{
|
9 | required: true,
|
10 | nullMsg: '内容不能为空!',
|
11 | errorMsg: '内容输入错误',
|
12 | placement: 'top'
|
13 | ...
|
14 | }
|
15 | }
|
16 | })
|
17 |
|
18 | *params*:
|
19 |
|
20 | `meta`: 字段信息集合,其中的key为字段名,value为字段属性信息,属性信息可自定义
|
21 |
|
22 | ---
|
23 | ## required
|
24 |
|
25 | `required`:指定输入字段是否为必填项,默认为`false`
|
26 |
|
27 | | Key | Value | 说明 |
|
28 | | -------- | ----- | ------- |
|
29 | | required | true | 字段为必填项 |
|
30 | | required | false | 字段为非必填项 |
|
31 |
|
32 |
|
33 |
|
34 | ---
|
35 |
|
36 |
|
37 | ## validType
|
38 |
|
39 | `validType`:验证输入类型,默认值为`null`
|
40 |
|
41 | | Key | Value | 说明 |
|
42 | | --------- | -------- | -------- |
|
43 | | validType | integer | 输入需为整数 |
|
44 | | validType | float | 输入需为浮点数 |
|
45 | | validType | zipCode | 输入需为邮编 |
|
46 | | validType | phone | 输入需为手机号码 |
|
47 | | validType | landline | 输入需为座机号码 |
|
48 | | validType | email | 输入需为邮箱 |
|
49 | | validType | url | 输入需为网址 |
|
50 | | validType | datetime | 输入需为日期 |
|
51 |
|
52 |
|
53 |
|
54 | ***
|
55 |
|
56 |
|
57 | ## nullMsg/errorMsg
|
58 |
|
59 | `nullMsg`:输入为空时的提示信息
|
60 |
|
61 | `errorMsg`:输入错误时的提示信息
|
62 |
|
63 | | Key | Value | 说明 |
|
64 | | -------- | ------------------ | ---------- |
|
65 | | nullMsg | 内容自定义:输入为空显示的内容 | 输入为空时的提示信息 |
|
66 | | errorMsg | 内容自定义:输入错误时显示的内容 | 输入错误时的提示信息 |
|
67 |
|
68 |
|
69 |
|
70 | ---
|
71 | ## reg
|
72 |
|
73 | `reg`:设置正则匹配
|
74 |
|
75 | | Key | Value | 说明 |
|
76 | | ------ | --------- | ---------- |
|
77 | | reg | 正则表达式 | 文本框需要匹配的正则 |
|
78 |
|
79 |
|
80 |
|
81 | ---
|
82 | ## notipFlag
|
83 |
|
84 | `notipFlag`:错误信息提示方式是否为`tooltip`,默认为`false`
|
85 |
|
86 | | Key | Value | 说明 |
|
87 | | --------- | ----- | ------------------ |
|
88 | | notipFlag | false| 错误信息提示为tips形式 |
|
89 | | notipFlag | true| 错误信息提示自定义,不为tips形式 |
|
90 |
|
91 |
|
92 |
|
93 | ---
|
94 | ## tipId
|
95 | `tipId`: 指定`tooltip`显示位置,其值为显示dom元素的id,默认为空,使用默认的`tooltip`
|
96 |
|
97 | | Key | Value | 说明 |
|
98 | | ----- | ----- | ----------------- |
|
99 | | tipId | ' ' | 使用默认的tooltip显示tip |
|
100 | | tipId | id | 使用自定义的id元素显示tip |
|
101 |
|
102 |
|
103 |
|
104 | ---
|
105 | ## hasSuccess
|
106 | `hasSuccess`:输入正确后是否提示。默认为`false`
|
107 |
|
108 | | Key | Value | 说明 |
|
109 | | ---------- | ----- | -------- |
|
110 | | hasSuccess | true | 输入正确后提示 |
|
111 | | hasSuccess | false | 输入正确后不提示 |
|
112 |
|
113 |
|
114 |
|
115 | ---
|
116 | ## successId
|
117 | `successId`:指定正确提示信息的位置,其值为正确dom元素的id,默认在输入框的后面显示
|
118 |
|
119 | | Key | Value | 说明 |
|
120 | | --------- | ----- | --------------- |
|
121 | | successId | id | 使用自定义的id元素显示正确提示信息 |
|
122 |
|
123 | `successId`能正常显示的前提是`hasSuccess:true`
|
124 |
|
125 |
|
126 |
|
127 | ---
|
128 |
|
129 | ## placement
|
130 |
|
131 | `placement`:提示框位置,默认为`top`
|
132 |
|
133 | | Key | Value | 说明 |
|
134 | | --------- | ------ | ---- |
|
135 | | placement | top | 上部显示 |
|
136 | | placement | bottom | 底部显示 |
|
137 | | placement | left | 左边显示 |
|
138 | | placement | right | 右边显示 |
|
139 |
|
140 |
|
141 | ---
|
142 | ## minLength&maxLength
|
143 |
|
144 | 字符串长度,注意`type`类型`string`
|
145 |
|
146 |
|
147 | | Key | Value | 说明 |
|
148 | | --------- | ----- | ---- |
|
149 | | minLength | num | 最小长度 |
|
150 | | maxLength | num | 最大长度 |
|
151 |
|
152 |
|
153 |
|
154 | ---
|
155 | ## 数值区间
|
156 |
|
157 | 数值区间,注意`type`类型`integer`或`float`
|
158 |
|
159 |
|
160 | | Key | Value | 说明 |
|
161 | | -------- | ----- | --------- |
|
162 | | min | num | 最小数值(包含) |
|
163 | | max | num | 最大数值(包含) |
|
164 | | minNotEq | num | 最小数值(不包含) |
|
165 | | maxNotEq | num | 最大数值(不包含) |
|
166 |
|
167 |
|
168 |
|
169 | ---
|
170 |
|
171 | ## 基本示例
|
172 |
|
173 |
|
174 | ##Validate
|
175 |
|
176 | 本例实现如下效果:
|
177 |
|
178 | * 基本的validate API测试
|
179 |
|
180 |
|
181 |
|
182 | <div class="example-content"> |
183 | HTML
|
184 | u-meta:框架特有标记,框架通过识别此标记创建对应UI组件,以及进行数据绑定
|
185 | id,type.data,field为必选项
|
186 | id:创建组件唯一标识
|
187 | type:创建组件对应的类型
|
188 | data:指定数据模型中的数据集
|
189 | field:绑定数据集中对应的字段
|
190 | -->
|
191 | <div class="u-form-group">
|
192 | <label>验证测试用例</label>
|
193 | <div class="u-input-group u-has-feedback" u-meta='{"id":"f1field","type":"string","data":"dt1","field":"f1"}'>
|
194 | <div class="u-input-group-before" style="color: red;">*</div>
|
195 | <input type="text" class="u-form-control">
|
196 | </div>
|
197 | </div>
|
198 | </div>
|
199 | <div class="example-content ex-hide"><script>// JS
|
200 |
|
201 | var app,viewModel;
|
202 |
|
203 | viewModel = {
|
204 | dt1: new u.DataTable({
|
205 | meta:{
|
206 | f1:{type:'string',required:true,maxLength:8,minLength:3},
|
207 | f2:{type:'string',required:true,maxLength:8,minLength:3,notipFlag: true,
|
208 | hasSuccess: true},
|
209 | }
|
210 | })
|
211 | };
|
212 |
|
213 |
|
214 | app = u.createApp({
|
215 | el:'body',
|
216 | model:viewModel
|
217 | });
|
218 |
|
219 | var r = viewModel.dt1.createEmptyRow();
|
220 | </script></div>
|
221 | <div class="examples-code"><pre><code><!--
|
222 | HTML
|
223 | u-meta:框架特有标记,框架通过识别此标记创建对应UI组件,以及进行数据绑定
|
224 | id,type.data,field为必选项
|
225 | id:创建组件唯一标识
|
226 | type:创建组件对应的类型
|
227 | data:指定数据模型中的数据集
|
228 | field:绑定数据集中对应的字段
|
229 | -->
|
230 | <div class="u-form-group">
|
231 | <label>验证测试用例</label>
|
232 | <div class="u-input-group u-has-feedback" u-meta='{"id":"f1field","type":"string","data":"dt1","field":"f1"}'>
|
233 | <div class="u-input-group-before" style="color: red;">*</div>
|
234 | <input type="text" class="u-form-control">
|
235 | </div>
|
236 | </div>
|
237 | </code></pre>
|
238 | </div>
|
239 | <div class="examples-code"><pre><code>// JS
|
240 |
|
241 | var app,viewModel;
|
242 |
|
243 | viewModel = {
|
244 | dt1: new u.DataTable({
|
245 | meta:{
|
246 | f1:{type:'string',required:true,maxLength:8,minLength:3},
|
247 | f2:{type:'string',required:true,maxLength:8,minLength:3,notipFlag: true,
|
248 | hasSuccess: true},
|
249 | }
|
250 | })
|
251 | };
|
252 |
|
253 |
|
254 | app = u.createApp({
|
255 | el:'body',
|
256 | model:viewModel
|
257 | });
|
258 |
|
259 | var r = viewModel.dt1.createEmptyRow();</code></pre>
|
260 | </div>
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | [试一试](http://design.yyuap.com/dist/pages/webIDE/index.html#/demos/kero/validate) |
\ | No newline at end of file |