@conform-to/react 0.7.0-pre.2 → 0.7.0
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 +35 -47
- package/helpers.d.ts +11 -2
- package/helpers.js +38 -31
- package/helpers.mjs +31 -31
- package/hooks.d.ts +11 -18
- package/hooks.js +151 -177
- package/hooks.mjs +151 -175
- package/package.json +2 -2
package/hooks.js
CHANGED
|
@@ -129,7 +129,7 @@ function useFormError(ref, config) {
|
|
|
129
129
|
* @see https://conform.guide/api/react#useform
|
|
130
130
|
*/
|
|
131
131
|
function useForm() {
|
|
132
|
-
var
|
|
132
|
+
var _config$lastSubmissio2;
|
|
133
133
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
134
134
|
var configRef = useConfigRef(config);
|
|
135
135
|
var ref = useFormRef(config.ref);
|
|
@@ -150,26 +150,36 @@ function useForm() {
|
|
|
150
150
|
[scope]: submission.error[scope]
|
|
151
151
|
};
|
|
152
152
|
}, [config.lastSubmission]);
|
|
153
|
+
// This payload from lastSubmission is only useful before hydration
|
|
154
|
+
// After hydration, any new payload on lastSubmission will be ignored
|
|
155
|
+
var [lastSubmissionPayload, setLastSubmissionPayload] = react.useState((_config$lastSubmissio2 = config.lastSubmission) === null || _config$lastSubmissio2 === void 0 ? void 0 : _config$lastSubmissio2.payload);
|
|
153
156
|
var fieldset = useFieldset(ref, {
|
|
154
|
-
defaultValue:
|
|
157
|
+
defaultValue: lastSubmissionPayload !== null && lastSubmissionPayload !== void 0 ? lastSubmissionPayload : config.defaultValue,
|
|
155
158
|
initialError,
|
|
156
159
|
constraint: config.constraint,
|
|
157
160
|
form: config.id
|
|
158
161
|
});
|
|
162
|
+
var lastSubmissionRef = react.useRef(config.lastSubmission);
|
|
163
|
+
useSafeLayoutEffect(() => {
|
|
164
|
+
if (lastSubmissionRef.current !== config.lastSubmission && config.lastSubmission === null) {
|
|
165
|
+
var _ref$current;
|
|
166
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.reset();
|
|
167
|
+
}
|
|
168
|
+
lastSubmissionRef.current = config.lastSubmission;
|
|
169
|
+
}, [ref, config.lastSubmission]);
|
|
159
170
|
react.useEffect(() => {
|
|
160
171
|
// custom validate handler
|
|
161
|
-
var createValidateHandler =
|
|
172
|
+
var createValidateHandler = type => event => {
|
|
162
173
|
var field = event.target;
|
|
163
174
|
var form = ref.current;
|
|
164
175
|
var {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
shouldRevalidate = 'onInput'
|
|
176
|
+
shouldValidate = 'onSubmit',
|
|
177
|
+
shouldRevalidate = shouldValidate
|
|
168
178
|
} = configRef.current;
|
|
169
179
|
if (!form || !dom.isFocusableFormControl(field) || field.form !== form || !field.name) {
|
|
170
180
|
return;
|
|
171
181
|
}
|
|
172
|
-
if (field.dataset.conformTouched ? shouldRevalidate ===
|
|
182
|
+
if (field.dataset.conformTouched ? shouldRevalidate === type : shouldValidate === type) {
|
|
173
183
|
dom.requestIntent(form, dom.validate(field.name));
|
|
174
184
|
}
|
|
175
185
|
};
|
|
@@ -191,11 +201,12 @@ function useForm() {
|
|
|
191
201
|
}
|
|
192
202
|
|
|
193
203
|
// Reset all field state
|
|
194
|
-
for (var
|
|
195
|
-
delete
|
|
196
|
-
|
|
204
|
+
for (var _element of dom.getFormControls(form)) {
|
|
205
|
+
delete _element.dataset.conformTouched;
|
|
206
|
+
_element.setCustomValidity('');
|
|
197
207
|
}
|
|
198
208
|
setErrors([]);
|
|
209
|
+
setLastSubmissionPayload(undefined);
|
|
199
210
|
};
|
|
200
211
|
var handleInput = createValidateHandler('onInput');
|
|
201
212
|
var handleBlur = createValidateHandler('onBlur');
|
|
@@ -234,12 +245,12 @@ function useForm() {
|
|
|
234
245
|
var {
|
|
235
246
|
errors: _errors,
|
|
236
247
|
shouldServerValidate
|
|
237
|
-
} = Object.entries(submission.error).reduce((result,
|
|
238
|
-
var [, error] =
|
|
248
|
+
} = Object.entries(submission.error).reduce((result, _ref) => {
|
|
249
|
+
var [, error] = _ref;
|
|
239
250
|
for (var message of normalizeError(error)) {
|
|
240
|
-
if (message === VALIDATION_UNDEFINED) {
|
|
251
|
+
if (message === dom.VALIDATION_UNDEFINED) {
|
|
241
252
|
result.shouldServerValidate = true;
|
|
242
|
-
} else if (message !== VALIDATION_SKIPPED) {
|
|
253
|
+
} else if (message !== dom.VALIDATION_SKIPPED) {
|
|
243
254
|
result.errors.push(message);
|
|
244
255
|
}
|
|
245
256
|
}
|
|
@@ -309,8 +320,8 @@ function useFieldset(ref, config) {
|
|
|
309
320
|
var fieldsetConfig = config;
|
|
310
321
|
var constraint = (_fieldsetConfig$const = fieldsetConfig.constraint) === null || _fieldsetConfig$const === void 0 ? void 0 : _fieldsetConfig$const[key];
|
|
311
322
|
var errors = error === null || error === void 0 ? void 0 : error[key];
|
|
312
|
-
var initialError = Object.entries((_fieldsetConfig$initi = fieldsetConfig.initialError) !== null && _fieldsetConfig$initi !== void 0 ? _fieldsetConfig$initi : {}).reduce((result,
|
|
313
|
-
var [name, message] =
|
|
323
|
+
var initialError = Object.entries((_fieldsetConfig$initi = fieldsetConfig.initialError) !== null && _fieldsetConfig$initi !== void 0 ? _fieldsetConfig$initi : {}).reduce((result, _ref2) => {
|
|
324
|
+
var [name, message] = _ref2;
|
|
314
325
|
var [field, ...paths] = dom.getPaths(name);
|
|
315
326
|
if (field === key) {
|
|
316
327
|
result[dom.getName(paths)] = message;
|
|
@@ -416,12 +427,12 @@ function useFieldList(ref, config) {
|
|
|
416
427
|
document.removeEventListener('reset', resetHandler);
|
|
417
428
|
};
|
|
418
429
|
}, [ref, configRef, setError]);
|
|
419
|
-
return entries.map((
|
|
430
|
+
return entries.map((_ref3, index) => {
|
|
420
431
|
var _config$initialError, _config$defaultValue2;
|
|
421
|
-
var [key, defaultValue] =
|
|
432
|
+
var [key, defaultValue] = _ref3;
|
|
422
433
|
var errors = error[index];
|
|
423
|
-
var initialError = Object.entries((_config$initialError = config.initialError) !== null && _config$initialError !== void 0 ? _config$initialError : {}).reduce((result,
|
|
424
|
-
var [name, message] =
|
|
434
|
+
var initialError = Object.entries((_config$initialError = config.initialError) !== null && _config$initialError !== void 0 ? _config$initialError : {}).reduce((result, _ref4) => {
|
|
435
|
+
var [name, message] = _ref4;
|
|
425
436
|
var [field, ...paths] = dom.getPaths(name);
|
|
426
437
|
if (field === index) {
|
|
427
438
|
result[dom.getName(paths)] = message;
|
|
@@ -447,179 +458,144 @@ function useFieldList(ref, config) {
|
|
|
447
458
|
});
|
|
448
459
|
}
|
|
449
460
|
|
|
450
|
-
/**
|
|
451
|
-
* Triggering react custom change event
|
|
452
|
-
* Solution based on dom-testing-library
|
|
453
|
-
* @see https://github.com/facebook/react/issues/10135#issuecomment-401496776
|
|
454
|
-
* @see https://github.com/testing-library/dom-testing-library/blob/main/src/events.js#L104-L123
|
|
455
|
-
*/
|
|
456
|
-
function setNativeValue(element, value) {
|
|
457
|
-
if (element.value === value) {
|
|
458
|
-
// It will not trigger a change event if `element.value` is the same as the set value
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
var {
|
|
462
|
-
set: valueSetter
|
|
463
|
-
} = Object.getOwnPropertyDescriptor(element, 'value') || {};
|
|
464
|
-
var prototype = Object.getPrototypeOf(element);
|
|
465
|
-
var {
|
|
466
|
-
set: prototypeValueSetter
|
|
467
|
-
} = Object.getOwnPropertyDescriptor(prototype, 'value') || {};
|
|
468
|
-
if (prototypeValueSetter && valueSetter !== prototypeValueSetter) {
|
|
469
|
-
prototypeValueSetter.call(element, value);
|
|
470
|
-
} else {
|
|
471
|
-
if (valueSetter) {
|
|
472
|
-
valueSetter.call(element, value);
|
|
473
|
-
} else {
|
|
474
|
-
throw new Error('The given element does not have a value setter');
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
461
|
/**
|
|
480
462
|
* useLayoutEffect is client-only.
|
|
481
463
|
* This basically makes it a no-op on server
|
|
482
464
|
*/
|
|
483
465
|
var useSafeLayoutEffect = typeof document === 'undefined' ? react.useEffect : react.useLayoutEffect;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Returns a ref object and a set of helpers that dispatch corresponding dom event.
|
|
469
|
+
*
|
|
470
|
+
* @see https://conform.guide/api/react#useinputevent
|
|
471
|
+
*/
|
|
484
472
|
function useInputEvent(options) {
|
|
485
|
-
var ref = react.useRef(null);
|
|
486
473
|
var optionsRef = useConfigRef(options);
|
|
487
|
-
var
|
|
488
|
-
|
|
489
|
-
|
|
474
|
+
var eventDispatched = react.useRef({
|
|
475
|
+
onInput: false,
|
|
476
|
+
onFocus: false,
|
|
477
|
+
onBlur: false
|
|
478
|
+
});
|
|
490
479
|
useSafeLayoutEffect(() => {
|
|
491
|
-
var
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
focusDispatched.current = true;
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
var blurHandler = event => {
|
|
508
|
-
var input = getInputElement();
|
|
509
|
-
if (input && event.target === input) {
|
|
510
|
-
blurDispatched.current = true;
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
var submitHandler = event => {
|
|
514
|
-
var input = getInputElement();
|
|
515
|
-
if (input !== null && input !== void 0 && input.form && event.target === input.form) {
|
|
516
|
-
var _optionsRef$current2, _optionsRef$current2$;
|
|
517
|
-
(_optionsRef$current2 = optionsRef.current) === null || _optionsRef$current2 === void 0 ? void 0 : (_optionsRef$current2$ = _optionsRef$current2.onSubmit) === null || _optionsRef$current2$ === void 0 ? void 0 : _optionsRef$current2$.call(_optionsRef$current2, event);
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
var resetHandler = event => {
|
|
521
|
-
var input = getInputElement();
|
|
522
|
-
if (input !== null && input !== void 0 && input.form && event.target === input.form) {
|
|
523
|
-
var _optionsRef$current3, _optionsRef$current3$;
|
|
524
|
-
(_optionsRef$current3 = optionsRef.current) === null || _optionsRef$current3 === void 0 ? void 0 : (_optionsRef$current3$ = _optionsRef$current3.onReset) === null || _optionsRef$current3$ === void 0 ? void 0 : _optionsRef$current3$.call(_optionsRef$current3, event);
|
|
525
|
-
}
|
|
480
|
+
var createEventListner = listener => {
|
|
481
|
+
return event => {
|
|
482
|
+
var _optionsRef$current, _optionsRef$current2, _optionsRef$current3;
|
|
483
|
+
var element = typeof ((_optionsRef$current = optionsRef.current) === null || _optionsRef$current === void 0 ? void 0 : _optionsRef$current.ref) === 'function' ? (_optionsRef$current2 = optionsRef.current) === null || _optionsRef$current2 === void 0 ? void 0 : _optionsRef$current2.ref() : (_optionsRef$current3 = optionsRef.current) === null || _optionsRef$current3 === void 0 ? void 0 : _optionsRef$current3.ref.current;
|
|
484
|
+
if (dom.isFieldElement(element) && (listener === 'onReset' ? event.target === element.form : event.target === element)) {
|
|
485
|
+
var _optionsRef$current4, _optionsRef$current4$;
|
|
486
|
+
if (listener !== 'onReset') {
|
|
487
|
+
console.log(listener, 'dispatched');
|
|
488
|
+
eventDispatched.current[listener] = true;
|
|
489
|
+
}
|
|
490
|
+
(_optionsRef$current4 = optionsRef.current) === null || _optionsRef$current4 === void 0 ? void 0 : (_optionsRef$current4$ = _optionsRef$current4[listener]) === null || _optionsRef$current4$ === void 0 ? void 0 : _optionsRef$current4$.call(_optionsRef$current4, event);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
526
493
|
};
|
|
494
|
+
var inputHandler = createEventListner('onInput');
|
|
495
|
+
var focusHandler = createEventListner('onFocus');
|
|
496
|
+
var blurHandler = createEventListner('onBlur');
|
|
497
|
+
var resetHandler = createEventListner('onReset');
|
|
498
|
+
|
|
499
|
+
// focus/blur event does not bubble
|
|
527
500
|
document.addEventListener('input', inputHandler, true);
|
|
528
501
|
document.addEventListener('focus', focusHandler, true);
|
|
529
502
|
document.addEventListener('blur', blurHandler, true);
|
|
530
|
-
document.addEventListener('submit', submitHandler);
|
|
531
503
|
document.addEventListener('reset', resetHandler);
|
|
532
504
|
return () => {
|
|
533
505
|
document.removeEventListener('input', inputHandler, true);
|
|
534
506
|
document.removeEventListener('focus', focusHandler, true);
|
|
535
507
|
document.removeEventListener('blur', blurHandler, true);
|
|
536
|
-
document.removeEventListener('submit', submitHandler);
|
|
537
508
|
document.removeEventListener('reset', resetHandler);
|
|
538
509
|
};
|
|
539
510
|
}, []);
|
|
540
511
|
var control = react.useMemo(() => {
|
|
541
|
-
var
|
|
542
|
-
|
|
543
|
-
|
|
512
|
+
var dispatch = (listener, fn) => {
|
|
513
|
+
if (!eventDispatched.current[listener]) {
|
|
514
|
+
var _optionsRef$current5, _optionsRef$current6, _optionsRef$current7;
|
|
515
|
+
var _element2 = typeof ((_optionsRef$current5 = optionsRef.current) === null || _optionsRef$current5 === void 0 ? void 0 : _optionsRef$current5.ref) === 'function' ? (_optionsRef$current6 = optionsRef.current) === null || _optionsRef$current6 === void 0 ? void 0 : _optionsRef$current6.ref() : (_optionsRef$current7 = optionsRef.current) === null || _optionsRef$current7 === void 0 ? void 0 : _optionsRef$current7.ref.current;
|
|
516
|
+
if (!dom.isFieldElement(_element2)) {
|
|
517
|
+
console.warn('Failed to dispatch event; is the input mounted?');
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// To avoid recursion
|
|
522
|
+
eventDispatched.current[listener] = true;
|
|
523
|
+
fn(_element2);
|
|
524
|
+
}
|
|
525
|
+
eventDispatched.current[listener] = false;
|
|
544
526
|
};
|
|
545
527
|
return {
|
|
546
528
|
change(eventOrValue) {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
529
|
+
dispatch('onInput', element => {
|
|
530
|
+
if (element instanceof HTMLInputElement && (element.type === 'checkbox' || element.type === 'radio')) {
|
|
531
|
+
if (typeof eventOrValue !== 'boolean') {
|
|
532
|
+
throw new Error('You should pass a boolean when changing a checkbox or radio input');
|
|
533
|
+
}
|
|
534
|
+
element.checked = eventOrValue;
|
|
535
|
+
} else {
|
|
536
|
+
if (typeof eventOrValue === 'boolean') {
|
|
537
|
+
throw new Error('You can pass a boolean only when changing a checkbox or radio input');
|
|
538
|
+
}
|
|
539
|
+
var _value = typeof eventOrValue === 'string' ? eventOrValue : eventOrValue.target.value;
|
|
558
540
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
541
|
+
// No change event will triggered on React if `element.value` is updated
|
|
542
|
+
// before dispatching the event
|
|
543
|
+
if (element.value !== _value) {
|
|
544
|
+
/**
|
|
545
|
+
* Triggering react custom change event
|
|
546
|
+
* Solution based on dom-testing-library
|
|
547
|
+
* @see https://github.com/facebook/react/issues/10135#issuecomment-401496776
|
|
548
|
+
* @see https://github.com/testing-library/dom-testing-library/blob/main/src/events.js#L104-L123
|
|
549
|
+
*/
|
|
550
|
+
var {
|
|
551
|
+
set: valueSetter
|
|
552
|
+
} = Object.getOwnPropertyDescriptor(element, 'value') || {};
|
|
553
|
+
var prototype = Object.getPrototypeOf(element);
|
|
554
|
+
var {
|
|
555
|
+
set: prototypeValueSetter
|
|
556
|
+
} = Object.getOwnPropertyDescriptor(prototype, 'value') || {};
|
|
557
|
+
if (prototypeValueSetter && valueSetter !== prototypeValueSetter) {
|
|
558
|
+
prototypeValueSetter.call(element, _value);
|
|
559
|
+
} else {
|
|
560
|
+
if (valueSetter) {
|
|
561
|
+
valueSetter.call(element, _value);
|
|
562
|
+
} else {
|
|
563
|
+
throw new Error('The given element does not have a value setter');
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
563
568
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}));
|
|
574
|
-
// Reset the dispatched flag
|
|
575
|
-
changeDispatched.current = false;
|
|
569
|
+
// Dispatch input event with the updated input value
|
|
570
|
+
element.dispatchEvent(new InputEvent('input', {
|
|
571
|
+
bubbles: true
|
|
572
|
+
}));
|
|
573
|
+
// Dispatch change event (necessary for select to update the selected option)
|
|
574
|
+
element.dispatchEvent(new Event('change', {
|
|
575
|
+
bubbles: true
|
|
576
|
+
}));
|
|
577
|
+
});
|
|
576
578
|
},
|
|
577
579
|
focus() {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (focusDispatched.current) {
|
|
584
|
-
focusDispatched.current = false;
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
var focusinEvent = new FocusEvent('focusin', {
|
|
588
|
-
bubbles: true
|
|
580
|
+
dispatch('onFocus', element => {
|
|
581
|
+
element.dispatchEvent(new FocusEvent('focusin', {
|
|
582
|
+
bubbles: true
|
|
583
|
+
}));
|
|
584
|
+
element.dispatchEvent(new FocusEvent('focus'));
|
|
589
585
|
});
|
|
590
|
-
var focusEvent = new FocusEvent('focus');
|
|
591
|
-
input.dispatchEvent(focusinEvent);
|
|
592
|
-
input.dispatchEvent(focusEvent);
|
|
593
|
-
|
|
594
|
-
// Reset the dispatched flag
|
|
595
|
-
focusDispatched.current = false;
|
|
596
586
|
},
|
|
597
587
|
blur() {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
if (blurDispatched.current) {
|
|
604
|
-
blurDispatched.current = false;
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
var focusoutEvent = new FocusEvent('focusout', {
|
|
608
|
-
bubbles: true
|
|
588
|
+
dispatch('onBlur', element => {
|
|
589
|
+
element.dispatchEvent(new FocusEvent('focusout', {
|
|
590
|
+
bubbles: true
|
|
591
|
+
}));
|
|
592
|
+
element.dispatchEvent(new FocusEvent('blur'));
|
|
609
593
|
});
|
|
610
|
-
var blurEvent = new FocusEvent('blur');
|
|
611
|
-
input.dispatchEvent(focusoutEvent);
|
|
612
|
-
input.dispatchEvent(blurEvent);
|
|
613
|
-
|
|
614
|
-
// Reset the dispatched flag
|
|
615
|
-
blurDispatched.current = false;
|
|
616
594
|
}
|
|
617
595
|
};
|
|
618
596
|
}, [optionsRef]);
|
|
619
|
-
return
|
|
597
|
+
return control;
|
|
620
598
|
}
|
|
621
|
-
var VALIDATION_UNDEFINED = '__undefined__';
|
|
622
|
-
var VALIDATION_SKIPPED = '__skipped__';
|
|
623
599
|
var FORM_ERROR_ELEMENT_NAME = '__form__';
|
|
624
600
|
|
|
625
601
|
/**
|
|
@@ -646,28 +622,28 @@ function validateConstraint(options) {
|
|
|
646
622
|
}
|
|
647
623
|
return errors;
|
|
648
624
|
};
|
|
649
|
-
var formatMessages = (_options$formatMessag = options === null || options === void 0 ? void 0 : options.formatMessages) !== null && _options$formatMessag !== void 0 ? _options$formatMessag :
|
|
625
|
+
var formatMessages = (_options$formatMessag = options === null || options === void 0 ? void 0 : options.formatMessages) !== null && _options$formatMessag !== void 0 ? _options$formatMessag : _ref5 => {
|
|
650
626
|
var {
|
|
651
627
|
defaultErrors
|
|
652
|
-
} =
|
|
628
|
+
} = _ref5;
|
|
653
629
|
return defaultErrors;
|
|
654
630
|
};
|
|
655
631
|
return dom.parse(formData, {
|
|
656
632
|
resolve(payload, intent) {
|
|
657
633
|
var error = {};
|
|
658
634
|
var constraintPattern = /^constraint[A-Z][^A-Z]*$/;
|
|
659
|
-
var _loop = function _loop(
|
|
660
|
-
if (dom.isFieldElement(
|
|
635
|
+
var _loop = function _loop(_element3) {
|
|
636
|
+
if (dom.isFieldElement(_element3)) {
|
|
661
637
|
var _options$acceptMultip, _options$acceptMultip2;
|
|
662
|
-
var name =
|
|
663
|
-
var constraint = Object.entries(
|
|
664
|
-
var [name, attributeValue = ''] =
|
|
638
|
+
var name = _element3.name !== FORM_ERROR_ELEMENT_NAME ? _element3.name : '';
|
|
639
|
+
var constraint = Object.entries(_element3.dataset).reduce((result, _ref6) => {
|
|
640
|
+
var [name, attributeValue = ''] = _ref6;
|
|
665
641
|
if (constraintPattern.test(name)) {
|
|
666
642
|
var _options$constraint;
|
|
667
643
|
var constraintName = name.slice(10).toLowerCase();
|
|
668
644
|
var _validate = (_options$constraint = options.constraint) === null || _options$constraint === void 0 ? void 0 : _options$constraint[constraintName];
|
|
669
645
|
if (typeof _validate === 'function') {
|
|
670
|
-
result[constraintName] = _validate(
|
|
646
|
+
result[constraintName] = _validate(_element3.value, {
|
|
671
647
|
formData,
|
|
672
648
|
attributeValue
|
|
673
649
|
});
|
|
@@ -679,9 +655,9 @@ function validateConstraint(options) {
|
|
|
679
655
|
}, {});
|
|
680
656
|
var errors = formatMessages({
|
|
681
657
|
name,
|
|
682
|
-
validity:
|
|
658
|
+
validity: _element3.validity,
|
|
683
659
|
constraint,
|
|
684
|
-
defaultErrors: getDefaultErrors(
|
|
660
|
+
defaultErrors: getDefaultErrors(_element3.validity, constraint)
|
|
685
661
|
});
|
|
686
662
|
var shouldAcceptMultipleErrors = (_options$acceptMultip = options === null || options === void 0 ? void 0 : (_options$acceptMultip2 = options.acceptMultipleErrors) === null || _options$acceptMultip2 === void 0 ? void 0 : _options$acceptMultip2.call(options, {
|
|
687
663
|
name,
|
|
@@ -693,8 +669,8 @@ function validateConstraint(options) {
|
|
|
693
669
|
}
|
|
694
670
|
}
|
|
695
671
|
};
|
|
696
|
-
for (var
|
|
697
|
-
_loop(
|
|
672
|
+
for (var _element3 of options.form.elements) {
|
|
673
|
+
_loop(_element3);
|
|
698
674
|
}
|
|
699
675
|
return {
|
|
700
676
|
error
|
|
@@ -732,18 +708,18 @@ function reportSubmission(form, submission) {
|
|
|
732
708
|
}
|
|
733
709
|
var intent = dom.parseIntent(submission.intent);
|
|
734
710
|
var scope = getScope(intent);
|
|
735
|
-
for (var
|
|
736
|
-
var _elementName =
|
|
711
|
+
for (var _element4 of dom.getFormControls(form)) {
|
|
712
|
+
var _elementName = _element4.name !== FORM_ERROR_ELEMENT_NAME ? _element4.name : '';
|
|
737
713
|
var messages = normalizeError(submission.error[_elementName]);
|
|
738
714
|
if (scope === null || scope === _elementName) {
|
|
739
|
-
|
|
715
|
+
_element4.dataset.conformTouched = 'true';
|
|
740
716
|
}
|
|
741
|
-
if (!messages.includes(VALIDATION_SKIPPED) && !messages.includes(VALIDATION_UNDEFINED)) {
|
|
717
|
+
if (!messages.includes(dom.VALIDATION_SKIPPED) && !messages.includes(dom.VALIDATION_UNDEFINED)) {
|
|
742
718
|
var invalidEvent = new Event('invalid', {
|
|
743
719
|
cancelable: true
|
|
744
720
|
});
|
|
745
|
-
|
|
746
|
-
|
|
721
|
+
_element4.setCustomValidity(dom.getValidationMessage(messages));
|
|
722
|
+
_element4.dispatchEvent(invalidEvent);
|
|
747
723
|
}
|
|
748
724
|
}
|
|
749
725
|
if (!intent) {
|
|
@@ -761,8 +737,6 @@ function getScope(intent) {
|
|
|
761
737
|
}
|
|
762
738
|
|
|
763
739
|
exports.FORM_ERROR_ELEMENT_NAME = FORM_ERROR_ELEMENT_NAME;
|
|
764
|
-
exports.VALIDATION_SKIPPED = VALIDATION_SKIPPED;
|
|
765
|
-
exports.VALIDATION_UNDEFINED = VALIDATION_UNDEFINED;
|
|
766
740
|
exports.getScope = getScope;
|
|
767
741
|
exports.reportSubmission = reportSubmission;
|
|
768
742
|
exports.useFieldList = useFieldList;
|