|
216 | 216 | */ |
217 | 217 | Nette.validateForm = function (sender, onlyCheck) { |
218 | 218 | let form = sender.form || sender, |
219 | | - scope = false; |
| 219 | + scope; |
220 | 220 |
|
221 | 221 | Nette.formErrors = []; |
222 | 222 |
|
|
230 | 230 | } |
231 | 231 | } |
232 | 232 |
|
233 | | - let radios = {}; |
234 | | - |
235 | 233 | for (let elem of form.elements) { |
236 | 234 | if (elem.willValidate && elem.validity.badInput) { |
237 | 235 | elem.reportValidity(); |
238 | 236 | return false; |
239 | 237 | } |
240 | 238 | } |
241 | 239 |
|
242 | | - for (let elem of form.elements) { |
243 | | - if (elem.tagName && !(elem.tagName.toLowerCase() in {input: 1, select: 1, textarea: 1, button: 1})) { |
244 | | - continue; |
245 | | - |
246 | | - } else if (elem.type === 'radio') { |
247 | | - if (radios[elem.name]) { |
248 | | - continue; |
249 | | - } |
250 | | - radios[elem.name] = true; |
251 | | - } |
252 | | - |
253 | | - if ((scope && !elem.name.replace(/]\[|\[|]|$/g, '-').match(scope)) || Nette.isDisabled(elem)) { |
254 | | - continue; |
255 | | - } |
256 | | - |
257 | | - if (!Nette.validateControl(elem, null, onlyCheck) && !Nette.formErrors.length) { |
| 240 | + for (let elem of Array.from(form.elements)) { |
| 241 | + if (elem.getAttribute('data-nette-rules') |
| 242 | + && (!scope || elem.name.replace(/]\[|\[|]|$/g, '-').match(scope)) |
| 243 | + && !Nette.isDisabled(elem) |
| 244 | + && !Nette.validateControl(elem, null, onlyCheck) |
| 245 | + && !Nette.formErrors.length |
| 246 | + ) { |
258 | 247 | return false; |
259 | 248 | } |
260 | 249 | } |
|
600 | 589 | */ |
601 | 590 | Nette.toggleForm = function (form, event) { |
602 | 591 | formToggles = {}; |
603 | | - for (let i = 0; i < form.elements.length; i++) { |
604 | | - if (form.elements[i].tagName.toLowerCase() in {input: 1, select: 1, textarea: 1, button: 1}) { |
605 | | - Nette.toggleControl(form.elements[i], null, null, !event); |
| 592 | + for (let elem of Array.from(form.elements)) { |
| 593 | + if (elem.getAttribute('data-nette-rules')) { |
| 594 | + Nette.toggleControl(elem, null, null, !event); |
606 | 595 | } |
607 | 596 | } |
608 | 597 |
|
|
0 commit comments