@bookinglab/booking-ui-react 1.8.0 → 1.10.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 +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -787,7 +787,8 @@ var ContactDetailsForm = forwardRef(
|
|
|
787
787
|
className = "",
|
|
788
788
|
classNames = {},
|
|
789
789
|
fieldSettings = {},
|
|
790
|
-
hideSubmitButton = false
|
|
790
|
+
hideSubmitButton = false,
|
|
791
|
+
isSubmitted = false
|
|
791
792
|
}, ref) => {
|
|
792
793
|
const formId = useId();
|
|
793
794
|
const [firstName, setFirstName] = useState(initialValues?.firstName || "");
|
|
@@ -828,6 +829,7 @@ var ContactDetailsForm = forwardRef(
|
|
|
828
829
|
}, [fieldSettings]);
|
|
829
830
|
const validateQuestionField = useCallback((question, value) => {
|
|
830
831
|
if (question.detail_type === "heading") return null;
|
|
832
|
+
if (question.disabled) return null;
|
|
831
833
|
if (question.required) {
|
|
832
834
|
if (value === void 0 || value === "" || value === null) {
|
|
833
835
|
return `${question.name} is required`;
|
|
@@ -1006,7 +1008,7 @@ var ContactDetailsForm = forwardRef(
|
|
|
1006
1008
|
const errorId = `${fieldId}-error`;
|
|
1007
1009
|
const isDisabled = getFieldDisabled(name);
|
|
1008
1010
|
const isRequired = getFieldRequired(name);
|
|
1009
|
-
const error = contactTouched[name] ? contactErrors[name] : void 0;
|
|
1011
|
+
const error = contactTouched[name] || isSubmitted ? contactErrors[name] : void 0;
|
|
1010
1012
|
const hasError = !!error;
|
|
1011
1013
|
return /* @__PURE__ */ jsxs("div", { className: styles.fieldWrapper, children: [
|
|
1012
1014
|
/* @__PURE__ */ jsxs("label", { htmlFor: fieldId, className: styles.label, children: [
|
|
@@ -1036,8 +1038,9 @@ var ContactDetailsForm = forwardRef(
|
|
|
1036
1038
|
const fieldId = `${formId}-q-${question.id}`;
|
|
1037
1039
|
const errorId = `${fieldId}-error`;
|
|
1038
1040
|
const value = questionValues[question.id];
|
|
1039
|
-
const error = questionTouched[question.id] ? questionErrors[question.id] : void 0;
|
|
1041
|
+
const error = questionTouched[question.id] || isSubmitted ? questionErrors[question.id] : void 0;
|
|
1040
1042
|
const hasError = !!error;
|
|
1043
|
+
const isDisabled = !!question.disabled;
|
|
1041
1044
|
const ariaProps = {
|
|
1042
1045
|
"aria-invalid": hasError ? true : void 0,
|
|
1043
1046
|
"aria-describedby": hasError ? errorId : void 0,
|
|
@@ -1058,10 +1061,11 @@ var ContactDetailsForm = forwardRef(
|
|
|
1058
1061
|
id: fieldId,
|
|
1059
1062
|
type: "text",
|
|
1060
1063
|
value: value || "",
|
|
1064
|
+
disabled: isDisabled,
|
|
1061
1065
|
onChange: (e) => handleQuestionChange(question.id, e.target.value),
|
|
1062
1066
|
onBlur: () => handleQuestionBlur(question.id),
|
|
1063
1067
|
placeholder: question.settings?.placeholder,
|
|
1064
|
-
className: inputClasses(hasError),
|
|
1068
|
+
className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
|
|
1065
1069
|
...ariaProps
|
|
1066
1070
|
}
|
|
1067
1071
|
),
|
|
@@ -1079,11 +1083,12 @@ var ContactDetailsForm = forwardRef(
|
|
|
1079
1083
|
{
|
|
1080
1084
|
id: fieldId,
|
|
1081
1085
|
value: value || "",
|
|
1086
|
+
disabled: isDisabled,
|
|
1082
1087
|
onChange: (e) => handleQuestionChange(question.id, e.target.value),
|
|
1083
1088
|
onBlur: () => handleQuestionBlur(question.id),
|
|
1084
1089
|
placeholder: question.settings?.placeholder,
|
|
1085
1090
|
rows: 4,
|
|
1086
|
-
className: inputClasses(hasError),
|
|
1091
|
+
className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
|
|
1087
1092
|
...ariaProps
|
|
1088
1093
|
}
|
|
1089
1094
|
),
|
|
@@ -1101,9 +1106,10 @@ var ContactDetailsForm = forwardRef(
|
|
|
1101
1106
|
{
|
|
1102
1107
|
id: fieldId,
|
|
1103
1108
|
value: value ?? "",
|
|
1109
|
+
disabled: isDisabled,
|
|
1104
1110
|
onChange: (e) => handleQuestionChange(question.id, e.target.value),
|
|
1105
1111
|
onBlur: () => handleQuestionBlur(question.id),
|
|
1106
|
-
className: inputClasses(hasError),
|
|
1112
|
+
className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
|
|
1107
1113
|
...ariaProps,
|
|
1108
1114
|
children: [
|
|
1109
1115
|
/* @__PURE__ */ jsx("option", { value: "", children: "Select an option" }),
|
|
@@ -1126,12 +1132,13 @@ var ContactDetailsForm = forwardRef(
|
|
|
1126
1132
|
id: fieldId,
|
|
1127
1133
|
type: "number",
|
|
1128
1134
|
value: value ?? "",
|
|
1135
|
+
disabled: isDisabled,
|
|
1129
1136
|
onChange: (e) => handleQuestionChange(question.id, e.target.value ? Number(e.target.value) : ""),
|
|
1130
1137
|
onBlur: () => handleQuestionBlur(question.id),
|
|
1131
1138
|
min: question.settings?.min,
|
|
1132
1139
|
max: question.settings?.max,
|
|
1133
1140
|
placeholder: question.settings?.placeholder,
|
|
1134
|
-
className: inputClasses(hasError),
|
|
1141
|
+
className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
|
|
1135
1142
|
...ariaProps
|
|
1136
1143
|
}
|
|
1137
1144
|
),
|
|
@@ -1150,9 +1157,10 @@ var ContactDetailsForm = forwardRef(
|
|
|
1150
1157
|
id: fieldId,
|
|
1151
1158
|
type: "date",
|
|
1152
1159
|
value: value || "",
|
|
1160
|
+
disabled: isDisabled,
|
|
1153
1161
|
onChange: (e) => handleQuestionChange(question.id, e.target.value),
|
|
1154
1162
|
onBlur: () => handleQuestionBlur(question.id),
|
|
1155
|
-
className: inputClasses(hasError),
|
|
1163
|
+
className: cx2(inputClasses(hasError), isDisabled ? "opacity-50 cursor-not-allowed" : ""),
|
|
1156
1164
|
...ariaProps
|
|
1157
1165
|
}
|
|
1158
1166
|
),
|
|
@@ -1168,9 +1176,10 @@ var ContactDetailsForm = forwardRef(
|
|
|
1168
1176
|
id: fieldId,
|
|
1169
1177
|
type: "checkbox",
|
|
1170
1178
|
checked: !!value,
|
|
1179
|
+
disabled: isDisabled,
|
|
1171
1180
|
onChange: (e) => handleQuestionChange(question.id, e.target.checked),
|
|
1172
1181
|
onBlur: () => handleQuestionBlur(question.id),
|
|
1173
|
-
className: styles.checkbox,
|
|
1182
|
+
className: cx2(styles.checkbox, isDisabled ? "opacity-50 cursor-not-allowed" : ""),
|
|
1174
1183
|
...ariaProps
|
|
1175
1184
|
}
|
|
1176
1185
|
),
|
|
@@ -1186,6 +1195,12 @@ var ContactDetailsForm = forwardRef(
|
|
|
1186
1195
|
return null;
|
|
1187
1196
|
}
|
|
1188
1197
|
};
|
|
1198
|
+
useEffect(() => {
|
|
1199
|
+
if (isSubmitted) {
|
|
1200
|
+
validateAllContacts();
|
|
1201
|
+
validateAllQuestions();
|
|
1202
|
+
}
|
|
1203
|
+
}, [isSubmitted]);
|
|
1189
1204
|
useEffect(() => {
|
|
1190
1205
|
if (hideSubmitButton && _onChange) {
|
|
1191
1206
|
const contactValid = !contactFields.some((f) => {
|