@wix/form-public 0.552.0 → 0.554.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/dist/index.cjs CHANGED
@@ -44616,14 +44616,26 @@ var challengesSingleChoiceViewer = {
44616
44616
  normalizeLoadedValue: acceptOnlyValidOptionByLabel
44617
44617
  };
44618
44618
 
44619
+ // ../form-fields/dist/esm/field-viewer/prehydration-readers.js
44620
+ var getCheckedInputs = (element) => Array.from(element.querySelectorAll('input[type="checkbox"]:checked, input[type="radio"]:checked'));
44621
+ var readIsChecked = (element) => getCheckedInputs(element).length > 0;
44622
+ var readCheckedValues = (element) => getCheckedInputs(element).map((input) => input.value);
44623
+ var readCheckedValue = (element) => getCheckedInputs(element)[0]?.value;
44624
+ var readCheckedRating = (element) => {
44625
+ const rating = readCheckedValue(element);
44626
+ return rating ? Number(rating) : void 0;
44627
+ };
44628
+
44619
44629
  // ../form-fields/dist/esm/fields/checkbox-group/definition-viewer.js
44620
44630
  var checkboxGroupViewer = {
44621
- normalizeLoadedValue: removeInvalidOptions
44631
+ normalizeLoadedValue: removeInvalidOptions,
44632
+ readPrehydrationValue: readCheckedValues
44622
44633
  };
44623
44634
 
44624
44635
  // ../form-fields/dist/esm/fields/checkbox/definition-viewer.js
44625
44636
  var checkboxViewer = {
44626
- normalizeLoadedValue: acceptBooleanValue
44637
+ normalizeLoadedValue: acceptBooleanValue,
44638
+ readPrehydrationValue: readIsChecked
44627
44639
  };
44628
44640
 
44629
44641
  // ../form-fields/dist/esm/fields/contacts-address/definition-viewer.js
@@ -44699,7 +44711,8 @@ var contactsPositionViewer = {
44699
44711
 
44700
44712
  // ../form-fields/dist/esm/fields/contacts-subscribe/definition-viewer.js
44701
44713
  var contactsSubscribeViewer = {
44702
- normalizeLoadedValue: acceptBooleanValue
44714
+ normalizeLoadedValue: acceptBooleanValue,
44715
+ readPrehydrationValue: readIsChecked
44703
44716
  };
44704
44717
 
44705
44718
  // ../form-fields/dist/esm/fields/contacts-tax-id/definition-viewer.js
@@ -44755,12 +44768,14 @@ var dateTimeInputViewer = {
44755
44768
 
44756
44769
  // ../form-fields/dist/esm/fields/dext-checkbox-group/definition-viewer.js
44757
44770
  var dextCheckboxGroupViewer = {
44758
- normalizeLoadedValue: removeInvalidOptions
44771
+ normalizeLoadedValue: removeInvalidOptions,
44772
+ readPrehydrationValue: readCheckedValues
44759
44773
  };
44760
44774
 
44761
44775
  // ../form-fields/dist/esm/fields/dext-checkbox/definition-viewer.js
44762
44776
  var dextCheckboxViewer = {
44763
- normalizeLoadedValue: acceptBooleanValue
44777
+ normalizeLoadedValue: acceptBooleanValue,
44778
+ readPrehydrationValue: readIsChecked
44764
44779
  };
44765
44780
 
44766
44781
  // ../form-fields/dist/esm/fields/dext-date-picker/definition-viewer.js
@@ -44795,17 +44810,20 @@ var dextPhoneViewer = {
44795
44810
 
44796
44811
  // ../form-fields/dist/esm/fields/dext-radio-group/definition-viewer.js
44797
44812
  var dextRadioGroupViewer = {
44798
- normalizeLoadedValue: acceptOnlyValidOptionByLabel
44813
+ normalizeLoadedValue: acceptOnlyValidOptionByLabel,
44814
+ readPrehydrationValue: readCheckedValue
44799
44815
  };
44800
44816
 
44801
44817
  // ../form-fields/dist/esm/fields/dext-rating-input/definition-viewer.js
44802
44818
  var dextRatingInputViewer = {
44803
- normalizeLoadedValue: acceptRatingValue
44819
+ normalizeLoadedValue: acceptRatingValue,
44820
+ readPrehydrationValue: readCheckedRating
44804
44821
  };
44805
44822
 
44806
44823
  // ../form-fields/dist/esm/fields/dext-tags/definition-viewer.js
44807
44824
  var dextTagsViewer = {
44808
- normalizeLoadedValue: removeInvalidOptions
44825
+ normalizeLoadedValue: removeInvalidOptions,
44826
+ readPrehydrationValue: readCheckedValues
44809
44827
  };
44810
44828
 
44811
44829
  // ../form-fields/dist/esm/fields/dext-text-area/definition-viewer.js
@@ -44900,7 +44918,8 @@ var ecomPhoneViewer = {
44900
44918
 
44901
44919
  // ../form-fields/dist/esm/fields/ecom-subscription-checkbox/definition-viewer.js
44902
44920
  var ecomSubscriptionCheckboxViewer = {
44903
- normalizeLoadedValue: acceptBooleanValue
44921
+ normalizeLoadedValue: acceptBooleanValue,
44922
+ readPrehydrationValue: readIsChecked
44904
44923
  };
44905
44924
 
44906
44925
  // ../form-fields/dist/esm/fields/events-repeater/events-repeater-normalize-value.js
@@ -44933,7 +44952,8 @@ var eventsRepeaterViewer = {
44933
44952
 
44934
44953
  // ../form-fields/dist/esm/fields/events-rsvp/definition-viewer.js
44935
44954
  var eventsRsvpViewer = {
44936
- normalizeLoadedValue: acceptOnlyValidOptionByValue
44955
+ normalizeLoadedValue: acceptOnlyValidOptionByValue,
44956
+ readPrehydrationValue: readCheckedValue
44937
44957
  };
44938
44958
 
44939
44959
  // ../form-fields/dist/esm/fields/file-upload/definition-viewer.js
@@ -44989,7 +45009,8 @@ var fullNameViewer = {
44989
45009
 
44990
45010
  // ../form-fields/dist/esm/fields/image-choice/definition-viewer.js
44991
45011
  var imageChoiceViewer = {
44992
- normalizeLoadedValue: removeInvalidOptions
45012
+ normalizeLoadedValue: removeInvalidOptions,
45013
+ readPrehydrationValue: readCheckedValues
44993
45014
  };
44994
45015
 
44995
45016
  // ../form-fields/dist/esm/fields/mla-address-line-2/definition-viewer.js
@@ -45090,7 +45111,8 @@ var quizNumberInputViewer = {
45090
45111
 
45091
45112
  // ../form-fields/dist/esm/fields/quiz-radio-group/definition-viewer.js
45092
45113
  var quizRadioGroupViewer = {
45093
- normalizeLoadedValue: acceptOnlyValidOptionByLabel
45114
+ normalizeLoadedValue: acceptOnlyValidOptionByLabel,
45115
+ readPrehydrationValue: readCheckedValue
45094
45116
  };
45095
45117
 
45096
45118
  // ../form-fields/dist/esm/fields/quiz-text-input/definition-viewer.js
@@ -45100,12 +45122,14 @@ var quizTextInputViewer = {
45100
45122
 
45101
45123
  // ../form-fields/dist/esm/fields/radio-group/definition-viewer.js
45102
45124
  var radioGroupViewer = {
45103
- normalizeLoadedValue: acceptOnlyValidOptionByLabel
45125
+ normalizeLoadedValue: acceptOnlyValidOptionByLabel,
45126
+ readPrehydrationValue: readCheckedValue
45104
45127
  };
45105
45128
 
45106
45129
  // ../form-fields/dist/esm/fields/rating-input/definition-viewer.js
45107
45130
  var ratingInputViewer = {
45108
- normalizeLoadedValue: acceptRatingValue
45131
+ normalizeLoadedValue: acceptRatingValue,
45132
+ readPrehydrationValue: readCheckedRating
45109
45133
  };
45110
45134
 
45111
45135
  // ../form-fields/dist/esm/fields/service-dropdown/definition-viewer.js
@@ -45125,7 +45149,8 @@ var signatureViewer = {
45125
45149
 
45126
45150
  // ../form-fields/dist/esm/fields/tags/definition-viewer.js
45127
45151
  var tagsViewer = {
45128
- normalizeLoadedValue: removeInvalidOptions
45152
+ normalizeLoadedValue: removeInvalidOptions,
45153
+ readPrehydrationValue: readCheckedValues
45129
45154
  };
45130
45155
 
45131
45156
  // ../form-fields/dist/esm/fields/text-area/definition-viewer.js
@@ -45630,6 +45655,7 @@ var InputField = ({ field, errors, values, onFieldChange, onBlur, onFocus, Field
45630
45655
  fieldType: field.fieldType,
45631
45656
  FieldLayout,
45632
45657
  autoComplete: FIELD_VIEWERS[field.fieldType]?.autoComplete,
45658
+ readPrehydrationValue: FIELD_VIEWERS[field.fieldType]?.readPrehydrationValue,
45633
45659
  requiredIndicatorType: requiredIndicator,
45634
45660
  requiredIndicatorPlacement
45635
45661
  };
@@ -49007,21 +49033,21 @@ function useAddressForms() {
49007
49033
  }
49008
49034
 
49009
49035
  // ../form-fields/dist/esm/services/prehydration-values.js
49010
- var isEmptyInputValue = (value) => value === void 0 || value === null || value === "";
49036
+ var isEmptyInputValue = (value) => value === void 0 || value === null || value === "" || value === false || Array.isArray(value) && value.length === 0;
49011
49037
  var isNested = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
49012
- var fill = (values, [key, ...rest], text) => {
49038
+ var fill = (values, [key, ...rest], value) => {
49013
49039
  const current = values[key];
49014
49040
  if (rest.length === 0) {
49015
49041
  return isEmptyInputValue(current) ? {
49016
49042
  ...values,
49017
- [key]: text
49043
+ [key]: value
49018
49044
  } : values;
49019
49045
  }
49020
49046
  if (!isEmptyInputValue(current) && !isNested(current)) {
49021
49047
  return values;
49022
49048
  }
49023
49049
  const nested = isNested(current) ? current : {};
49024
- const filled = fill(nested, rest, text);
49050
+ const filled = fill(nested, rest, value);
49025
49051
  return filled === nested ? values : {
49026
49052
  ...values,
49027
49053
  [key]: filled
@@ -49036,8 +49062,8 @@ var read = (values, [key, ...rest]) => {
49036
49062
  };
49037
49063
  var mergePrehydrationValues = (values, pending) => {
49038
49064
  let result2 = values;
49039
- for (const [path, text] of pending) {
49040
- result2 = fill(result2, path.split(FIELD_PATH_SEPARATOR), text);
49065
+ for (const [path, value] of pending) {
49066
+ result2 = fill(result2, path.split(FIELD_PATH_SEPARATOR), value);
49041
49067
  }
49042
49068
  return result2;
49043
49069
  };
@@ -49059,18 +49085,20 @@ var forgetPrehydrationValues = (pending, previousValues, nextValues) => {
49059
49085
 
49060
49086
  // ../form-fields/dist/esm/contexts/prehydration-values-context.js
49061
49087
  var PrehydrationValuesContext = /* @__PURE__ */ React172.createContext(void 0);
49088
+ var readText = (element) => element.value;
49062
49089
  var useKeepPrehydrationValue = (ref) => {
49063
49090
  const registry = React172.useContext(PrehydrationValuesContext);
49064
- const { path, value } = useFieldPropsV2();
49091
+ const { path, value, readPrehydrationValue = readText } = useFieldPropsV2();
49065
49092
  const mountedFieldRef = React172.useRef({
49066
49093
  path,
49067
49094
  value,
49068
- registry
49095
+ registry,
49096
+ read: readPrehydrationValue
49069
49097
  });
49070
49098
  React172.useEffect(() => {
49071
49099
  const field = mountedFieldRef.current;
49072
- const domValue = ref.current?.value;
49073
- if (field.registry && domValue && isEmptyInputValue(field.value)) {
49100
+ const domValue = ref.current ? field.read(ref.current) : void 0;
49101
+ if (field.registry && !isEmptyInputValue(domValue) && isEmptyInputValue(field.value)) {
49074
49102
  field.registry.current.set(field.path, domValue);
49075
49103
  }
49076
49104
  }, [
@@ -51143,7 +51171,9 @@ var useSubmit = ({ validateAndScrollToError, submitAction, onSubmit, onSubmitSuc
51143
51171
  ]);
51144
51172
  const submitForm = React172.useCallback(async () => {
51145
51173
  const errors = await validateAndScrollToError(values);
51146
- onSubmit?.();
51174
+ if (onSubmit?.() === false) {
51175
+ return;
51176
+ }
51147
51177
  reportSubmitFormBi({
51148
51178
  status: BiFormSubmissionStatus.INIT
51149
51179
  });
@@ -52598,6 +52628,7 @@ var CheckboxContainer = ({ children, className }) => {
52598
52628
  preventScroll: true
52599
52629
  });
52600
52630
  }, id6);
52631
+ useKeepPrehydrationValue(ref);
52601
52632
  const labelElement = findChildOfType(children, CheckboxContainer.RichTextLabel);
52602
52633
  const inputElement = findChildOfType(children, CheckboxContainer.Input);
52603
52634
  const handleChange = React172.useCallback((isSelected) => {
@@ -52689,6 +52720,8 @@ var CheckboxGroup = ({ children, className }) => {
52689
52720
  const props2 = useFieldPropsV2();
52690
52721
  const { id: id6, value, onChange, disabled, required, onBlur, onFocus, hasError, FieldLayout } = props2;
52691
52722
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
52723
+ const groupRef = React172.useRef(null);
52724
+ useKeepPrehydrationValue(groupRef);
52692
52725
  const labelElement = findChildOfType(children, CheckboxGroup.Label);
52693
52726
  const optionsElement = findChildOfType(children, CheckboxGroup.Options);
52694
52727
  const descriptionElement = findChildOfType(children, CheckboxGroup.Description);
@@ -52712,6 +52745,7 @@ var CheckboxGroup = ({ children, className }) => {
52712
52745
  onBlur,
52713
52746
  onFocus
52714
52747
  }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.CheckboxGroup, {
52748
+ ref: groupRef,
52715
52749
  className,
52716
52750
  "aria-labelledby": labelId,
52717
52751
  value: _value,
@@ -56647,6 +56681,8 @@ var getOtherValue2 = (value, addOtherLabel) => {
56647
56681
  var RadioGroup = ({ children, className }) => {
56648
56682
  const { id: id6, value, onChange, disabled, readOnly, required, onBlur, onFocus, hasError, FieldLayout, options } = useFieldPropsV2();
56649
56683
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
56684
+ const groupRef = React172.useRef(null);
56685
+ useKeepPrehydrationValue(groupRef);
56650
56686
  const labelElement = findChildOfType(children, RadioGroup.Label);
56651
56687
  const optionsElement = findChildOfType(children, RadioGroup.Options);
56652
56688
  const descriptionElement = findChildOfType(children, RadioGroup.Description);
@@ -56658,6 +56694,7 @@ var RadioGroup = ({ children, className }) => {
56658
56694
  as: "div"
56659
56695
  }),
56660
56696
  renderInput: () => /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.RadioGroup, {
56697
+ ref: groupRef,
56661
56698
  id: inputId,
56662
56699
  className,
56663
56700
  "aria-labelledby": labelId,
@@ -61084,6 +61121,7 @@ var Ratings = ({ children, className, getReactionLabel }) => {
61084
61121
  const { inputId } = useFieldAttributes();
61085
61122
  const [hovered, setHovered] = React172.useState();
61086
61123
  const containerRef = React172.useRef(null);
61124
+ useKeepPrehydrationValue(containerRef);
61087
61125
  const ratingElement = findChildOfType(children, Ratings.Rating);
61088
61126
  const ratingValues = [
61089
61127
  "1",
@@ -63265,6 +63303,8 @@ var Control8 = ({ children, className }) => {
63265
63303
  var Tags = ({ children }) => {
63266
63304
  const { id: id6, value, onChange, FieldLayout, required, disabled, readOnly, hasError, onBlur, onFocus } = useFieldPropsV2();
63267
63305
  const { inputId, labelId, ariaDescribedBy } = useFieldAttributes();
63306
+ const groupRef = React172.useRef(null);
63307
+ useKeepPrehydrationValue(groupRef);
63268
63308
  const selectedValues = React172.useMemo(() => value || [], [
63269
63309
  value
63270
63310
  ]);
@@ -63283,6 +63323,7 @@ var Tags = ({ children }) => {
63283
63323
  onBlur,
63284
63324
  onFocus
63285
63325
  }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.CheckboxGroup, {
63326
+ ref: groupRef,
63286
63327
  "aria-labelledby": labelId,
63287
63328
  value: selectedValues,
63288
63329
  onChange,