@italia/popover 0.1.0-alpha.2 → 1.0.0-alpha.4
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/dist/src/it-popover.js +59 -8
- package/dist/src/it-popover.js.map +1 -1
- package/package.json +7 -4
package/dist/src/it-popover.js
CHANGED
|
@@ -436,6 +436,7 @@ const interactions = new WeakMap();
|
|
|
436
436
|
/** A reactive controller to allow form controls to participate in form submission, validation, etc. */
|
|
437
437
|
class FormControlController {
|
|
438
438
|
constructor(host, options) {
|
|
439
|
+
this.submittedOnce = false;
|
|
439
440
|
this.handleFormData = (event) => {
|
|
440
441
|
// console.log('handleFormData');
|
|
441
442
|
const disabled = this.options.disabled(this.host);
|
|
@@ -457,6 +458,17 @@ class FormControlController {
|
|
|
457
458
|
event.formData.append(name, value);
|
|
458
459
|
}
|
|
459
460
|
break;
|
|
461
|
+
case 'it-checkbox':
|
|
462
|
+
if (this.host.checked) {
|
|
463
|
+
if (event.formData.getAll(name).indexOf(value) < 0) {
|
|
464
|
+
// handle group checkbox
|
|
465
|
+
event.formData.append(name, value);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
break;
|
|
469
|
+
case 'it-checkbox-group':
|
|
470
|
+
// non settare valori in formData, perchè ogni singola checkbox setta il suo valore
|
|
471
|
+
break;
|
|
460
472
|
default:
|
|
461
473
|
if (Array.isArray(value)) {
|
|
462
474
|
value.forEach((val) => {
|
|
@@ -478,13 +490,30 @@ class FormControlController {
|
|
|
478
490
|
this.setUserInteracted(control, true);
|
|
479
491
|
});
|
|
480
492
|
}
|
|
481
|
-
|
|
493
|
+
const resReportValidity = reportValidity(this.host);
|
|
494
|
+
if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {
|
|
482
495
|
event.preventDefault();
|
|
483
496
|
// event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta
|
|
497
|
+
// Scroll al primo controllo non valido
|
|
498
|
+
const formControls = formCollections.get(this.form);
|
|
499
|
+
if (formControls) {
|
|
500
|
+
for (const control of formControls) {
|
|
501
|
+
if (!control.validity?.valid) {
|
|
502
|
+
// Scroll smooth verso il controllo non valido
|
|
503
|
+
control.scrollIntoView({
|
|
504
|
+
behavior: 'smooth',
|
|
505
|
+
block: 'center',
|
|
506
|
+
});
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
484
511
|
}
|
|
512
|
+
this.submittedOnce = true;
|
|
485
513
|
};
|
|
486
514
|
this.handleFormReset = () => {
|
|
487
515
|
this.options.setValue(this.host, '');
|
|
516
|
+
this.submittedOnce = false;
|
|
488
517
|
this.setUserInteracted(this.host, false);
|
|
489
518
|
interactions.set(this.host, []);
|
|
490
519
|
};
|
|
@@ -649,6 +678,7 @@ class FormControlController {
|
|
|
649
678
|
if (!formCollection) {
|
|
650
679
|
return;
|
|
651
680
|
}
|
|
681
|
+
this.submittedOnce = false;
|
|
652
682
|
// Remove this host from the form's collection
|
|
653
683
|
formCollection.delete(this.host);
|
|
654
684
|
// Check to make sure there's no other form controls in the collection. If we do this
|
|
@@ -745,6 +775,10 @@ class FormControlController {
|
|
|
745
775
|
host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
|
|
746
776
|
host.toggleAttribute('data-user-valid', isValid && hasInteracted);
|
|
747
777
|
}
|
|
778
|
+
userInteracted() {
|
|
779
|
+
const hasInteracted = Boolean(userInteractedControls.has(this.host));
|
|
780
|
+
return hasInteracted;
|
|
781
|
+
}
|
|
748
782
|
/**
|
|
749
783
|
* Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
|
|
750
784
|
* that affects constraint validation changes so the component receives the correct validity states.
|
|
@@ -781,6 +815,7 @@ const translation = {
|
|
|
781
815
|
$name: 'Italiano',
|
|
782
816
|
$dir: 'ltr',
|
|
783
817
|
validityRequired: 'Questo campo è obbligatorio.',
|
|
818
|
+
validityGroupRequired: "Scegli almeno un'opzione",
|
|
784
819
|
validityPattern: 'Il valore non corrisponde al formato richiesto.',
|
|
785
820
|
validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',
|
|
786
821
|
validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',
|
|
@@ -825,24 +860,27 @@ class FormControl extends BaseLocalizedComponent {
|
|
|
825
860
|
this.maxlength = -1;
|
|
826
861
|
/** If the input is required. */
|
|
827
862
|
this.required = false;
|
|
863
|
+
/* For grouped input, like checkbox-group */
|
|
864
|
+
this.isInGroup = false;
|
|
828
865
|
this.validationMessage = '';
|
|
829
866
|
}
|
|
830
867
|
/** Gets the validity state object */
|
|
831
868
|
get validity() {
|
|
832
869
|
return this.inputElement?.validity;
|
|
833
870
|
}
|
|
871
|
+
/** Gets the associated form, if one exists. */
|
|
872
|
+
getForm() {
|
|
873
|
+
return this.formControlController.getForm();
|
|
874
|
+
}
|
|
834
875
|
// Form validation methods
|
|
835
876
|
checkValidity() {
|
|
836
877
|
const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser
|
|
837
878
|
return inputValid;
|
|
838
879
|
}
|
|
839
|
-
/** Gets the associated form, if one exists. */
|
|
840
|
-
getForm() {
|
|
841
|
-
return this.formControlController.getForm();
|
|
842
|
-
}
|
|
843
880
|
/** Checks for validity and shows the browser's validation message if the control is invalid. */
|
|
844
881
|
reportValidity() {
|
|
845
|
-
const ret = this.inputElement.checkValidity();
|
|
882
|
+
// const ret = this.inputElement.checkValidity();
|
|
883
|
+
const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella
|
|
846
884
|
this.handleValidationMessages();
|
|
847
885
|
return ret; // this.inputElement.reportValidity();
|
|
848
886
|
}
|
|
@@ -887,7 +925,8 @@ class FormControl extends BaseLocalizedComponent {
|
|
|
887
925
|
handleValidationMessages() {
|
|
888
926
|
if (!this.customValidation) {
|
|
889
927
|
const _v = this.inputElement.validity;
|
|
890
|
-
|
|
928
|
+
const isRequiredHandledByGroup = this.isInGroup === true;
|
|
929
|
+
if (_v.valueMissing && !isRequiredHandledByGroup) {
|
|
891
930
|
this.setCustomValidity(this.$t('validityRequired'));
|
|
892
931
|
}
|
|
893
932
|
else if (_v.patternMismatch) {
|
|
@@ -958,7 +997,7 @@ class FormControl extends BaseLocalizedComponent {
|
|
|
958
997
|
if (this.customValidation) {
|
|
959
998
|
this.setCustomValidity(this.validationText ?? '');
|
|
960
999
|
}
|
|
961
|
-
else {
|
|
1000
|
+
else if (this.formControlController.userInteracted()) {
|
|
962
1001
|
this.formControlController.updateValidity();
|
|
963
1002
|
}
|
|
964
1003
|
}
|
|
@@ -1026,11 +1065,23 @@ __decorate([
|
|
|
1026
1065
|
,
|
|
1027
1066
|
__metadata("design:type", Object)
|
|
1028
1067
|
], FormControl.prototype, "required", void 0);
|
|
1068
|
+
__decorate([
|
|
1069
|
+
property({ type: Boolean }),
|
|
1070
|
+
__metadata("design:type", Object)
|
|
1071
|
+
], FormControl.prototype, "isInGroup", void 0);
|
|
1029
1072
|
__decorate([
|
|
1030
1073
|
state(),
|
|
1031
1074
|
__metadata("design:type", Object)
|
|
1032
1075
|
], FormControl.prototype, "validationMessage", void 0);
|
|
1033
1076
|
|
|
1077
|
+
if (typeof window !== 'undefined') {
|
|
1078
|
+
window._itAnalytics = window._itAnalytics || {};
|
|
1079
|
+
window._itAnalytics = {
|
|
1080
|
+
...window._itAnalytics,
|
|
1081
|
+
version: '1.0.0-alpha.4',
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1034
1085
|
/**
|
|
1035
1086
|
* Custom positioning reference element.
|
|
1036
1087
|
* @see https://floating-ui.com/docs/virtual-elements
|