@uxf/form 11.88.2 → 11.88.3

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.
@@ -39,6 +39,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.GpsInput = GpsInput;
41
41
  const translations_1 = require("@uxf/core-react/translations");
42
+ const is_empty_1 = require("@uxf/core/utils/is-empty");
43
+ const is_nil_1 = require("@uxf/core/utils/is-nil");
44
+ const is_not_empty_1 = require("@uxf/core/utils/is-not-empty");
42
45
  const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
43
46
  const text_input_1 = require("@uxf/ui/text-input");
44
47
  const tooltip_1 = require("@uxf/ui/tooltip");
@@ -102,7 +105,7 @@ function GpsInput(props) {
102
105
  const t = (0, translations_1.useUxfTranslation)();
103
106
  const id = (_a = props.id) !== null && _a !== void 0 ? _a : `${formContext.formId}__${props.name}`;
104
107
  const [visualValue, setVisualValue] = (0, react_1.useState)("");
105
- const [coordsFormatError, setCoordsFormatError] = (0, react_1.useState)(false);
108
+ const [hasCoordsFormatError, setHasCoordsFormatError] = (0, react_1.useState)(false);
106
109
  const { field, fieldState } = (0, react_hook_form_1.useController)({
107
110
  control: props.control,
108
111
  name: props.name,
@@ -112,12 +115,12 @@ function GpsInput(props) {
112
115
  ...(_b = props.rules) === null || _b === void 0 ? void 0 : _b.validate,
113
116
  req: (value) => {
114
117
  var _a;
115
- return props.isRequired && value === undefined
118
+ return ((0, is_nil_1.isNil)(value) || (0, is_empty_1.isEmpty)(value)) && props.isRequired
116
119
  ? ((_a = props.requiredMessage) !== null && _a !== void 0 ? _a : t("uxf-form-gps-input:validation.required", { value: value }))
117
120
  : undefined;
118
121
  },
119
122
  format: (value) => {
120
- return value === null
123
+ return value === null && hasCoordsFormatError
121
124
  ? t("uxf-form-gps-input:validation.invalid-coordinates", { value: value })
122
125
  : undefined;
123
126
  },
@@ -136,23 +139,28 @@ function GpsInput(props) {
136
139
  (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
137
140
  };
138
141
  const onChange = (value, event) => {
139
- var _a, _b;
142
+ var _a, _b, _c;
140
143
  setVisualValue(value);
141
- try {
142
- const coords = new coordinate_parser_1.default(value);
143
- setCoordsFormatError(false);
144
- field.onChange({ lat: coords.getLatitude(), lng: coords.getLongitude() });
145
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, value, event);
146
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
144
+ if ((0, is_not_empty_1.isNotEmpty)(value)) {
145
+ try {
146
+ const coords = new coordinate_parser_1.default(value);
147
+ setHasCoordsFormatError(false);
148
+ field.onChange({ lat: coords.getLatitude(), lng: coords.getLongitude() });
149
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, value, event);
150
+ }
151
+ catch {
152
+ setHasCoordsFormatError(true);
153
+ field.onChange(null);
154
+ (_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, value, event);
155
+ }
147
156
  }
148
- catch (e) {
149
- setCoordsFormatError(true);
150
- field.onChange(null);
151
- (_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, value, event);
157
+ else {
158
+ field.onChange(value);
159
+ (_c = props.onChange) === null || _c === void 0 ? void 0 : _c.call(props, value, event);
152
160
  }
153
161
  };
154
162
  const composedHelperText = (react_1.default.createElement(react_1.default.Fragment, null,
155
- fieldState.error && !coordsFormatError && !field.value
163
+ fieldState.error && !hasCoordsFormatError && !field.value
156
164
  ? `${fieldState.error.message}`
157
165
  : field.value
158
166
  ? `${field.value.lat}N, ${field.value.lng}E`
@@ -161,6 +169,6 @@ function GpsInput(props) {
161
169
  : t("uxf-form-gps-input:validation.empty-coordinates"),
162
170
  " ",
163
171
  getSupportedFormatsTooltip(t)));
164
- return (react_1.default.createElement(text_input_1.TextInput, { autoComplete: props.autoComplete, autoFocus: props.autoFocus, className: props.className, enterKeyHint: props.enterKeyHint, form: props.form, helperText: composedHelperText, hiddenLabel: props.hiddenLabel, id: id, inputMode: props.inputMode, isDisabled: formContext.isFormDisabled || props.isDisabled, isInvalid: ((0, is_not_nil_1.isNotNil)(fieldState.error) && !field.value) || coordsFormatError, isReadOnly: formContext.isFormReadOnly || props.isReadOnly, isRequired: props.isRequired, label: props.label, leftAddon: props.leftAddon, leftElement: props.leftElement, maxLength: props.maxLength, minLength: props.minLength, name: field.name, onBlur: onBlur, onChange: onChange, onFocus: props.onFocus, onKeyDown: props.onKeyDown, placeholder: props.placeholder, ref: field.ref, rightAddon: props.rightAddon, rightElement: props.rightElement, size: props.size, style: props.style, type: "text", value: visualValue, variant: props.variant }));
172
+ return (react_1.default.createElement(text_input_1.TextInput, { autoComplete: props.autoComplete, autoFocus: props.autoFocus, className: props.className, enterKeyHint: props.enterKeyHint, form: props.form, helperText: composedHelperText, hiddenLabel: props.hiddenLabel, id: id, inputMode: props.inputMode, isDisabled: formContext.isFormDisabled || props.isDisabled, isInvalid: ((0, is_not_nil_1.isNotNil)(fieldState.error) && !field.value) || hasCoordsFormatError, isReadOnly: formContext.isFormReadOnly || props.isReadOnly, isRequired: props.isRequired, label: props.label, leftAddon: props.leftAddon, leftElement: props.leftElement, maxLength: props.maxLength, minLength: props.minLength, name: field.name, onBlur: onBlur, onChange: onChange, onFocus: props.onFocus, onKeyDown: props.onKeyDown, placeholder: props.placeholder, ref: field.ref, rightAddon: props.rightAddon, rightElement: props.rightElement, size: props.size, style: props.style, type: "text", value: visualValue, variant: props.variant }));
165
173
  }
166
174
  GpsInput.displayName = "UxfFormGpsInput";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/form",
3
- "version": "11.88.2",
3
+ "version": "11.88.3",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"