@awell-health/ui-library 0.1.64 → 0.1.66
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.js +901 -657
- package/dist/types/atoms/inputField/InputField.d.ts +1 -1
- package/dist/types/hooks/useForm/helpers.d.ts +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/molecules/question/helpers/isValidEmail.d.ts +1 -0
- package/dist/types/types/generated/types-orchestration.d.ts +84 -72
- package/package.json +3 -5
package/dist/index.js
CHANGED
|
@@ -16114,8 +16114,11 @@ Check the top-level render call using <` + t + ">.");
|
|
|
16114
16114
|
})(exports.AllowedDatesOptions || (exports.AllowedDatesOptions = {}));
|
|
16115
16115
|
exports.ApiCallRequestMethod = void 0;
|
|
16116
16116
|
(function (ApiCallRequestMethod) {
|
|
16117
|
+
ApiCallRequestMethod["Delete"] = "DELETE";
|
|
16117
16118
|
ApiCallRequestMethod["Get"] = "GET";
|
|
16119
|
+
ApiCallRequestMethod["Patch"] = "PATCH";
|
|
16118
16120
|
ApiCallRequestMethod["Post"] = "POST";
|
|
16121
|
+
ApiCallRequestMethod["Put"] = "PUT";
|
|
16119
16122
|
})(exports.ApiCallRequestMethod || (exports.ApiCallRequestMethod = {}));
|
|
16120
16123
|
exports.ApiCallStatus = void 0;
|
|
16121
16124
|
(function (ApiCallStatus) {
|
|
@@ -16153,6 +16156,8 @@ Check the top-level render call using <` + t + ">.");
|
|
|
16153
16156
|
ConditionOperator["IsInRange"] = "IS_IN_RANGE";
|
|
16154
16157
|
ConditionOperator["IsLessThan"] = "IS_LESS_THAN";
|
|
16155
16158
|
ConditionOperator["IsLessThanOrEqualTo"] = "IS_LESS_THAN_OR_EQUAL_TO";
|
|
16159
|
+
ConditionOperator["IsLessThanXDaysAgo"] = "IS_LESS_THAN_X_DAYS_AGO";
|
|
16160
|
+
ConditionOperator["IsMoreThanXDaysAgo"] = "IS_MORE_THAN_X_DAYS_AGO";
|
|
16156
16161
|
ConditionOperator["IsNoneOf"] = "IS_NONE_OF";
|
|
16157
16162
|
ConditionOperator["IsNotEmpty"] = "IS_NOT_EMPTY";
|
|
16158
16163
|
ConditionOperator["IsNotEqualTo"] = "IS_NOT_EQUAL_TO";
|
|
@@ -16268,27 +16273,11 @@ Check the top-level render call using <` + t + ">.");
|
|
|
16268
16273
|
StakeholderClinicalAppRole["Patient"] = "PATIENT";
|
|
16269
16274
|
StakeholderClinicalAppRole["Physician"] = "PHYSICIAN";
|
|
16270
16275
|
})(exports.StakeholderClinicalAppRole || (exports.StakeholderClinicalAppRole = {}));
|
|
16271
|
-
exports.SwimlaneItemCategory = void 0;
|
|
16272
|
-
(function (SwimlaneItemCategory) {
|
|
16273
|
-
SwimlaneItemCategory["Action"] = "ACTION";
|
|
16274
|
-
SwimlaneItemCategory["PathwayEnd"] = "PATHWAY_END";
|
|
16275
|
-
SwimlaneItemCategory["PathwayStart"] = "PATHWAY_START";
|
|
16276
|
-
SwimlaneItemCategory["Step"] = "STEP";
|
|
16277
|
-
SwimlaneItemCategory["Track"] = "TRACK";
|
|
16278
|
-
SwimlaneItemCategory["TrackEnd"] = "TRACK_END";
|
|
16279
|
-
SwimlaneItemCategory["TrackStart"] = "TRACK_START";
|
|
16280
|
-
})(exports.SwimlaneItemCategory || (exports.SwimlaneItemCategory = {}));
|
|
16281
|
-
exports.SwimlaneItemType = void 0;
|
|
16282
|
-
(function (SwimlaneItemType) {
|
|
16283
|
-
SwimlaneItemType["Active"] = "active";
|
|
16284
|
-
SwimlaneItemType["Completed"] = "completed";
|
|
16285
|
-
SwimlaneItemType["Pending"] = "pending";
|
|
16286
|
-
SwimlaneItemType["Possible"] = "possible";
|
|
16287
|
-
})(exports.SwimlaneItemType || (exports.SwimlaneItemType = {}));
|
|
16288
16276
|
exports.UserQuestionType = void 0;
|
|
16289
16277
|
(function (UserQuestionType) {
|
|
16290
16278
|
UserQuestionType["Date"] = "DATE";
|
|
16291
16279
|
UserQuestionType["Description"] = "DESCRIPTION";
|
|
16280
|
+
UserQuestionType["Email"] = "EMAIL";
|
|
16292
16281
|
UserQuestionType["LongText"] = "LONG_TEXT";
|
|
16293
16282
|
UserQuestionType["MultipleChoice"] = "MULTIPLE_CHOICE";
|
|
16294
16283
|
UserQuestionType["MultipleChoiceGrid"] = "MULTIPLE_CHOICE_GRID";
|
|
@@ -35035,22 +35024,92 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35035
35024
|
|
|
35036
35025
|
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
35037
35026
|
|
|
35027
|
+
var isPlainObject = (tempObject) => {
|
|
35028
|
+
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
|
35029
|
+
return isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf');
|
|
35030
|
+
};
|
|
35031
|
+
|
|
35032
|
+
var isWeb = typeof window !== 'undefined' &&
|
|
35033
|
+
typeof window.HTMLElement !== 'undefined' &&
|
|
35034
|
+
typeof document !== 'undefined';
|
|
35035
|
+
|
|
35036
|
+
function cloneObject(data) {
|
|
35037
|
+
let copy;
|
|
35038
|
+
const isArray = Array.isArray(data);
|
|
35039
|
+
if (data instanceof Date) {
|
|
35040
|
+
copy = new Date(data);
|
|
35041
|
+
} else
|
|
35042
|
+
if (data instanceof Set) {
|
|
35043
|
+
copy = new Set(data);
|
|
35044
|
+
} else
|
|
35045
|
+
if (!(isWeb && (data instanceof Blob || data instanceof FileList)) && (
|
|
35046
|
+
isArray || isObject(data))) {
|
|
35047
|
+
copy = isArray ? [] : {};
|
|
35048
|
+
if (!isArray && !isPlainObject(data)) {
|
|
35049
|
+
copy = data;
|
|
35050
|
+
} else
|
|
35051
|
+
{
|
|
35052
|
+
for (const key in data) {
|
|
35053
|
+
if (data.hasOwnProperty(key)) {
|
|
35054
|
+
copy[key] = cloneObject(data[key]);
|
|
35055
|
+
}
|
|
35056
|
+
}
|
|
35057
|
+
}
|
|
35058
|
+
} else
|
|
35059
|
+
{
|
|
35060
|
+
return data;
|
|
35061
|
+
}
|
|
35062
|
+
return copy;
|
|
35063
|
+
}
|
|
35064
|
+
|
|
35038
35065
|
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
35039
35066
|
|
|
35040
35067
|
var isUndefined = (val) => val === undefined;
|
|
35041
35068
|
|
|
35042
|
-
var get = (
|
|
35043
|
-
if (!path || !isObject(
|
|
35069
|
+
var get = (object, path, defaultValue) => {
|
|
35070
|
+
if (!path || !isObject(object)) {
|
|
35044
35071
|
return defaultValue;
|
|
35045
35072
|
}
|
|
35046
|
-
const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key],
|
|
35047
|
-
return isUndefined(result) || result ===
|
|
35048
|
-
isUndefined(
|
|
35073
|
+
const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
|
|
35074
|
+
return isUndefined(result) || result === object ?
|
|
35075
|
+
isUndefined(object[path]) ?
|
|
35049
35076
|
defaultValue :
|
|
35050
|
-
|
|
35077
|
+
object[path] :
|
|
35051
35078
|
result;
|
|
35052
35079
|
};
|
|
35053
35080
|
|
|
35081
|
+
var isBoolean = (value) => typeof value === 'boolean';
|
|
35082
|
+
|
|
35083
|
+
var isKey = (value) => /^\w*$/.test(value);
|
|
35084
|
+
|
|
35085
|
+
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
|
35086
|
+
|
|
35087
|
+
var set = (object, path, value) => {
|
|
35088
|
+
let index = -1;
|
|
35089
|
+
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
35090
|
+
const length = tempPath.length;
|
|
35091
|
+
const lastIndex = length - 1;
|
|
35092
|
+
while (++index < length) {
|
|
35093
|
+
const key = tempPath[index];
|
|
35094
|
+
let newValue = value;
|
|
35095
|
+
if (index !== lastIndex) {
|
|
35096
|
+
const objValue = object[key];
|
|
35097
|
+
newValue =
|
|
35098
|
+
isObject(objValue) || Array.isArray(objValue) ?
|
|
35099
|
+
objValue :
|
|
35100
|
+
!isNaN(+tempPath[index + 1]) ?
|
|
35101
|
+
[] :
|
|
35102
|
+
{};
|
|
35103
|
+
}
|
|
35104
|
+
if (key === '__proto__') {
|
|
35105
|
+
return;
|
|
35106
|
+
}
|
|
35107
|
+
object[key] = newValue;
|
|
35108
|
+
object = object[key];
|
|
35109
|
+
}
|
|
35110
|
+
return object;
|
|
35111
|
+
};
|
|
35112
|
+
|
|
35054
35113
|
const EVENTS = {
|
|
35055
35114
|
BLUR: 'blur',
|
|
35056
35115
|
FOCUS_OUT: 'focusout',
|
|
@@ -35074,46 +35133,48 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35074
35133
|
|
|
35075
35134
|
|
|
35076
35135
|
const HookFormContext = /*#__PURE__*/React__default["default"].createContext(null);
|
|
35077
|
-
/**
|
|
35078
|
-
* This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
|
|
35079
|
-
*
|
|
35080
|
-
* @remarks
|
|
35081
|
-
* [API](https://react-hook-form.com/
|
|
35082
|
-
*
|
|
35083
|
-
* @returns return all useForm methods
|
|
35084
|
-
*
|
|
35085
|
-
* @example
|
|
35086
|
-
* ```tsx
|
|
35087
|
-
* function App() {
|
|
35088
|
-
* const methods = useForm();
|
|
35089
|
-
* const onSubmit = data => console.log(data);
|
|
35090
|
-
*
|
|
35091
|
-
* return (
|
|
35092
|
-
* <FormProvider {...methods} >
|
|
35093
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
35094
|
-
* <NestedInput />
|
|
35095
|
-
* <input type="submit" />
|
|
35096
|
-
* </form>
|
|
35097
|
-
* </FormProvider>
|
|
35098
|
-
* );
|
|
35099
|
-
* }
|
|
35100
|
-
*
|
|
35101
|
-
* function NestedInput() {
|
|
35102
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
|
35103
|
-
* return <input {...register("test")} />;
|
|
35104
|
-
* }
|
|
35105
|
-
* ```
|
|
35136
|
+
/**
|
|
35137
|
+
* This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
|
|
35138
|
+
*
|
|
35139
|
+
* @remarks
|
|
35140
|
+
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
35141
|
+
*
|
|
35142
|
+
* @returns return all useForm methods
|
|
35143
|
+
*
|
|
35144
|
+
* @example
|
|
35145
|
+
* ```tsx
|
|
35146
|
+
* function App() {
|
|
35147
|
+
* const methods = useForm();
|
|
35148
|
+
* const onSubmit = data => console.log(data);
|
|
35149
|
+
*
|
|
35150
|
+
* return (
|
|
35151
|
+
* <FormProvider {...methods} >
|
|
35152
|
+
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
35153
|
+
* <NestedInput />
|
|
35154
|
+
* <input type="submit" />
|
|
35155
|
+
* </form>
|
|
35156
|
+
* </FormProvider>
|
|
35157
|
+
* );
|
|
35158
|
+
* }
|
|
35159
|
+
*
|
|
35160
|
+
* function NestedInput() {
|
|
35161
|
+
* const { register } = useFormContext(); // retrieve all hook methods
|
|
35162
|
+
* return <input {...register("test")} />;
|
|
35163
|
+
* }
|
|
35164
|
+
* ```
|
|
35106
35165
|
*/
|
|
35107
35166
|
const useFormContext = () => React__default["default"].useContext(HookFormContext);
|
|
35108
35167
|
|
|
35109
|
-
var getProxyFormState = (formState,
|
|
35110
|
-
const result = {
|
|
35168
|
+
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
35169
|
+
const result = {
|
|
35170
|
+
defaultValues: control._defaultValues };
|
|
35171
|
+
|
|
35111
35172
|
for (const key in formState) {
|
|
35112
35173
|
Object.defineProperty(result, key, {
|
|
35113
35174
|
get: () => {
|
|
35114
35175
|
const _key = key;
|
|
35115
|
-
if (_proxyFormState[_key] !== VALIDATION_MODE.all) {
|
|
35116
|
-
_proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
|
|
35176
|
+
if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
|
|
35177
|
+
control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
|
|
35117
35178
|
}
|
|
35118
35179
|
localProxyFormState && (localProxyFormState[_key] = true);
|
|
35119
35180
|
return formState[_key];
|
|
@@ -35125,7 +35186,8 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35125
35186
|
|
|
35126
35187
|
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
|
35127
35188
|
|
|
35128
|
-
var shouldRenderFormState = (formStateData, _proxyFormState, isRoot) => {
|
|
35189
|
+
var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
|
|
35190
|
+
updateFormState(formStateData);
|
|
35129
35191
|
const { name, ...formState } = formStateData;
|
|
35130
35192
|
return isEmptyObject(formState) ||
|
|
35131
35193
|
Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
|
|
@@ -35135,12 +35197,12 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35135
35197
|
|
|
35136
35198
|
var convertToArrayPayload = (value) => Array.isArray(value) ? value : [value];
|
|
35137
35199
|
|
|
35138
|
-
var shouldSubscribeByName = (name, signalName, exact) =>
|
|
35139
|
-
name === signalName :
|
|
35140
|
-
!name ||
|
|
35200
|
+
var shouldSubscribeByName = (name, signalName, exact) => !name ||
|
|
35141
35201
|
!signalName ||
|
|
35142
35202
|
name === signalName ||
|
|
35143
35203
|
convertToArrayPayload(name).some((currentName) => currentName && (
|
|
35204
|
+
exact ?
|
|
35205
|
+
currentName === signalName :
|
|
35144
35206
|
currentName.startsWith(signalName) ||
|
|
35145
35207
|
signalName.startsWith(currentName)));
|
|
35146
35208
|
|
|
@@ -35148,187 +35210,161 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35148
35210
|
const _props = React__default["default"].useRef(props);
|
|
35149
35211
|
_props.current = props;
|
|
35150
35212
|
React__default["default"].useEffect(() => {
|
|
35151
|
-
const tearDown = (subscription) => {
|
|
35152
|
-
if (subscription) {
|
|
35153
|
-
subscription.unsubscribe();
|
|
35154
|
-
}
|
|
35155
|
-
};
|
|
35156
35213
|
const subscription = !props.disabled &&
|
|
35214
|
+
_props.current.subject &&
|
|
35157
35215
|
_props.current.subject.subscribe({
|
|
35158
|
-
next: _props.current.
|
|
35216
|
+
next: _props.current.next });
|
|
35159
35217
|
|
|
35160
|
-
return () =>
|
|
35218
|
+
return () => {
|
|
35219
|
+
subscription && subscription.unsubscribe();
|
|
35220
|
+
};
|
|
35161
35221
|
}, [props.disabled]);
|
|
35162
35222
|
}
|
|
35163
35223
|
|
|
35164
|
-
/**
|
|
35165
|
-
* This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
|
|
35166
|
-
*
|
|
35167
|
-
* @remarks
|
|
35168
|
-
* [API](https://react-hook-form.com/
|
|
35169
|
-
*
|
|
35170
|
-
* @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
|
|
35171
|
-
*
|
|
35172
|
-
* @example
|
|
35173
|
-
* ```tsx
|
|
35174
|
-
* function App() {
|
|
35175
|
-
* const { register, handleSubmit, control } = useForm({
|
|
35176
|
-
* defaultValues: {
|
|
35177
|
-
* firstName: "firstName"
|
|
35178
|
-
* }});
|
|
35179
|
-
* const { dirtyFields } = useFormState({
|
|
35180
|
-
* control
|
|
35181
|
-
* });
|
|
35182
|
-
* const onSubmit = (data) => console.log(data);
|
|
35183
|
-
*
|
|
35184
|
-
* return (
|
|
35185
|
-
* <form onSubmit={handleSubmit(onSubmit)}>
|
|
35186
|
-
* <input {...register("firstName")} placeholder="First Name" />
|
|
35187
|
-
* {dirtyFields.firstName && <p>Field is dirty.</p>}
|
|
35188
|
-
* <input type="submit" />
|
|
35189
|
-
* </form>
|
|
35190
|
-
* );
|
|
35191
|
-
* }
|
|
35192
|
-
* ```
|
|
35224
|
+
/**
|
|
35225
|
+
* This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
|
|
35226
|
+
*
|
|
35227
|
+
* @remarks
|
|
35228
|
+
* [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
|
|
35229
|
+
*
|
|
35230
|
+
* @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
|
|
35231
|
+
*
|
|
35232
|
+
* @example
|
|
35233
|
+
* ```tsx
|
|
35234
|
+
* function App() {
|
|
35235
|
+
* const { register, handleSubmit, control } = useForm({
|
|
35236
|
+
* defaultValues: {
|
|
35237
|
+
* firstName: "firstName"
|
|
35238
|
+
* }});
|
|
35239
|
+
* const { dirtyFields } = useFormState({
|
|
35240
|
+
* control
|
|
35241
|
+
* });
|
|
35242
|
+
* const onSubmit = (data) => console.log(data);
|
|
35243
|
+
*
|
|
35244
|
+
* return (
|
|
35245
|
+
* <form onSubmit={handleSubmit(onSubmit)}>
|
|
35246
|
+
* <input {...register("firstName")} placeholder="First Name" />
|
|
35247
|
+
* {dirtyFields.firstName && <p>Field is dirty.</p>}
|
|
35248
|
+
* <input type="submit" />
|
|
35249
|
+
* </form>
|
|
35250
|
+
* );
|
|
35251
|
+
* }
|
|
35252
|
+
* ```
|
|
35193
35253
|
*/
|
|
35194
35254
|
function useFormState(props) {
|
|
35195
35255
|
const methods = useFormContext();
|
|
35196
35256
|
const { control = methods.control, disabled, name, exact } = props || {};
|
|
35197
35257
|
const [formState, updateFormState] = React__default["default"].useState(control._formState);
|
|
35258
|
+
const _mounted = React__default["default"].useRef(true);
|
|
35198
35259
|
const _localProxyFormState = React__default["default"].useRef({
|
|
35199
35260
|
isDirty: false,
|
|
35261
|
+
isLoading: false,
|
|
35200
35262
|
dirtyFields: false,
|
|
35201
35263
|
touchedFields: false,
|
|
35264
|
+
validatingFields: false,
|
|
35202
35265
|
isValidating: false,
|
|
35203
35266
|
isValid: false,
|
|
35204
35267
|
errors: false });
|
|
35205
35268
|
|
|
35206
35269
|
const _name = React__default["default"].useRef(name);
|
|
35207
|
-
const _mounted = React__default["default"].useRef(true);
|
|
35208
35270
|
_name.current = name;
|
|
35209
|
-
const callback = React__default["default"].useCallback((value) => _mounted.current &&
|
|
35210
|
-
shouldSubscribeByName(_name.current, value.name, exact) &&
|
|
35211
|
-
shouldRenderFormState(value, _localProxyFormState.current) &&
|
|
35212
|
-
updateFormState({
|
|
35213
|
-
...control._formState,
|
|
35214
|
-
...value }),
|
|
35215
|
-
[control, exact]);
|
|
35216
35271
|
useSubscribe({
|
|
35217
35272
|
disabled,
|
|
35218
|
-
|
|
35273
|
+
next: (value) => _mounted.current &&
|
|
35274
|
+
shouldSubscribeByName(_name.current, value.name, exact) &&
|
|
35275
|
+
shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) &&
|
|
35276
|
+
updateFormState({
|
|
35277
|
+
...control._formState,
|
|
35278
|
+
...value }),
|
|
35279
|
+
|
|
35219
35280
|
subject: control._subjects.state });
|
|
35220
35281
|
|
|
35221
35282
|
React__default["default"].useEffect(() => {
|
|
35222
35283
|
_mounted.current = true;
|
|
35284
|
+
_localProxyFormState.current.isValid && control._updateValid(true);
|
|
35223
35285
|
return () => {
|
|
35224
35286
|
_mounted.current = false;
|
|
35225
35287
|
};
|
|
35226
|
-
}, []);
|
|
35227
|
-
return getProxyFormState(formState, control
|
|
35288
|
+
}, [control]);
|
|
35289
|
+
return getProxyFormState(formState, control, _localProxyFormState.current, false);
|
|
35228
35290
|
}
|
|
35229
35291
|
|
|
35230
35292
|
var isString = (value) => typeof value === 'string';
|
|
35231
35293
|
|
|
35232
|
-
var generateWatchOutput = (names, _names, formValues, isGlobal) => {
|
|
35233
|
-
const isArray = Array.isArray(names);
|
|
35294
|
+
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
|
|
35234
35295
|
if (isString(names)) {
|
|
35235
35296
|
isGlobal && _names.watch.add(names);
|
|
35236
|
-
return get(formValues, names);
|
|
35297
|
+
return get(formValues, names, defaultValue);
|
|
35237
35298
|
}
|
|
35238
|
-
if (isArray) {
|
|
35239
|
-
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
|
|
35240
|
-
get(formValues, fieldName)));
|
|
35299
|
+
if (Array.isArray(names)) {
|
|
35300
|
+
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
|
|
35241
35301
|
}
|
|
35242
35302
|
isGlobal && (_names.watchAll = true);
|
|
35243
35303
|
return formValues;
|
|
35244
35304
|
};
|
|
35245
35305
|
|
|
35246
|
-
|
|
35247
|
-
|
|
35248
|
-
|
|
35249
|
-
|
|
35250
|
-
|
|
35251
|
-
|
|
35252
|
-
|
|
35253
|
-
|
|
35254
|
-
|
|
35255
|
-
|
|
35256
|
-
|
|
35257
|
-
|
|
35258
|
-
*
|
|
35259
|
-
*
|
|
35260
|
-
*
|
|
35261
|
-
*
|
|
35262
|
-
* [API](https://react-hook-form.com/api/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
|
|
35263
|
-
*
|
|
35264
|
-
* @example
|
|
35265
|
-
* ```tsx
|
|
35266
|
-
* const { watch } = useForm();
|
|
35267
|
-
* const values = useWatch({
|
|
35268
|
-
* name: "fieldName"
|
|
35269
|
-
* control,
|
|
35270
|
-
* })
|
|
35271
|
-
* ```
|
|
35306
|
+
/**
|
|
35307
|
+
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
|
|
35308
|
+
*
|
|
35309
|
+
* @remarks
|
|
35310
|
+
*
|
|
35311
|
+
* [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
|
|
35312
|
+
*
|
|
35313
|
+
* @example
|
|
35314
|
+
* ```tsx
|
|
35315
|
+
* const { control } = useForm();
|
|
35316
|
+
* const values = useWatch({
|
|
35317
|
+
* name: "fieldName"
|
|
35318
|
+
* control,
|
|
35319
|
+
* })
|
|
35320
|
+
* ```
|
|
35272
35321
|
*/
|
|
35273
35322
|
function useWatch(props) {
|
|
35274
35323
|
const methods = useFormContext();
|
|
35275
35324
|
const { control = methods.control, name, defaultValue, disabled, exact } = props || {};
|
|
35276
35325
|
const _name = React__default["default"].useRef(name);
|
|
35277
35326
|
_name.current = name;
|
|
35278
|
-
const callback = React__default["default"].useCallback((formState) => {
|
|
35279
|
-
if (shouldSubscribeByName(_name.current, formState.name, exact)) {
|
|
35280
|
-
const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
|
|
35281
|
-
updateValue(isUndefined(_name.current) ||
|
|
35282
|
-
isObject(fieldValues) && !objectHasFunction(fieldValues) ?
|
|
35283
|
-
{ ...fieldValues } :
|
|
35284
|
-
Array.isArray(fieldValues) ?
|
|
35285
|
-
[...fieldValues] :
|
|
35286
|
-
isUndefined(fieldValues) ?
|
|
35287
|
-
defaultValue :
|
|
35288
|
-
fieldValues);
|
|
35289
|
-
}
|
|
35290
|
-
}, [control, exact, defaultValue]);
|
|
35291
35327
|
useSubscribe({
|
|
35292
35328
|
disabled,
|
|
35293
|
-
subject: control._subjects.
|
|
35294
|
-
|
|
35329
|
+
subject: control._subjects.values,
|
|
35330
|
+
next: (formState) => {
|
|
35331
|
+
if (shouldSubscribeByName(_name.current, formState.name, exact)) {
|
|
35332
|
+
updateValue(cloneObject(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, defaultValue)));
|
|
35333
|
+
}
|
|
35334
|
+
} });
|
|
35295
35335
|
|
|
35296
|
-
const [value, updateValue] = React__default["default"].useState(
|
|
35297
|
-
control.
|
|
35298
|
-
defaultValue);
|
|
35299
|
-
React__default["default"].useEffect(() => {
|
|
35300
|
-
control._removeUnmounted();
|
|
35301
|
-
});
|
|
35336
|
+
const [value, updateValue] = React__default["default"].useState(control._getWatch(name, defaultValue));
|
|
35337
|
+
React__default["default"].useEffect(() => control._removeUnmounted());
|
|
35302
35338
|
return value;
|
|
35303
35339
|
}
|
|
35304
35340
|
|
|
35305
|
-
/**
|
|
35306
|
-
* Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
|
|
35307
|
-
*
|
|
35308
|
-
* @remarks
|
|
35309
|
-
* [API](https://react-hook-form.com/
|
|
35310
|
-
*
|
|
35311
|
-
* @param props - the path name to the form field value, and validation rules.
|
|
35312
|
-
*
|
|
35313
|
-
* @returns field properties, field and form state. {@link UseControllerReturn}
|
|
35314
|
-
*
|
|
35315
|
-
* @example
|
|
35316
|
-
* ```tsx
|
|
35317
|
-
* function Input(props) {
|
|
35318
|
-
* const { field, fieldState, formState } = useController(props);
|
|
35319
|
-
* return (
|
|
35320
|
-
* <div>
|
|
35321
|
-
* <input {...field} placeholder={props.name} />
|
|
35322
|
-
* <p>{fieldState.isTouched && "Touched"}</p>
|
|
35323
|
-
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
35324
|
-
* </div>
|
|
35325
|
-
* );
|
|
35326
|
-
* }
|
|
35327
|
-
* ```
|
|
35341
|
+
/**
|
|
35342
|
+
* Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
|
|
35343
|
+
*
|
|
35344
|
+
* @remarks
|
|
35345
|
+
* [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
|
|
35346
|
+
*
|
|
35347
|
+
* @param props - the path name to the form field value, and validation rules.
|
|
35348
|
+
*
|
|
35349
|
+
* @returns field properties, field and form state. {@link UseControllerReturn}
|
|
35350
|
+
*
|
|
35351
|
+
* @example
|
|
35352
|
+
* ```tsx
|
|
35353
|
+
* function Input(props) {
|
|
35354
|
+
* const { field, fieldState, formState } = useController(props);
|
|
35355
|
+
* return (
|
|
35356
|
+
* <div>
|
|
35357
|
+
* <input {...field} placeholder={props.name} />
|
|
35358
|
+
* <p>{fieldState.isTouched && "Touched"}</p>
|
|
35359
|
+
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
35360
|
+
* </div>
|
|
35361
|
+
* );
|
|
35362
|
+
* }
|
|
35363
|
+
* ```
|
|
35328
35364
|
*/
|
|
35329
35365
|
function useController(props) {
|
|
35330
35366
|
const methods = useFormContext();
|
|
35331
|
-
const { name, control = methods.control, shouldUnregister } = props;
|
|
35367
|
+
const { name, disabled, control = methods.control, shouldUnregister } = props;
|
|
35332
35368
|
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
35333
35369
|
const value = useWatch({
|
|
35334
35370
|
control,
|
|
@@ -35342,50 +35378,67 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35342
35378
|
|
|
35343
35379
|
const _registerProps = React__default["default"].useRef(control.register(name, {
|
|
35344
35380
|
...props.rules,
|
|
35345
|
-
value
|
|
35381
|
+
value,
|
|
35382
|
+
...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}) }));
|
|
35346
35383
|
|
|
35347
35384
|
React__default["default"].useEffect(() => {
|
|
35385
|
+
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
35348
35386
|
const updateMounted = (name, value) => {
|
|
35349
35387
|
const field = get(control._fields, name);
|
|
35350
|
-
if (field) {
|
|
35388
|
+
if (field && field._f) {
|
|
35351
35389
|
field._f.mount = value;
|
|
35352
35390
|
}
|
|
35353
35391
|
};
|
|
35354
35392
|
updateMounted(name, true);
|
|
35393
|
+
if (_shouldUnregisterField) {
|
|
35394
|
+
const value = cloneObject(get(control._options.defaultValues, name));
|
|
35395
|
+
set(control._defaultValues, name, value);
|
|
35396
|
+
if (isUndefined(get(control._formValues, name))) {
|
|
35397
|
+
set(control._formValues, name, value);
|
|
35398
|
+
}
|
|
35399
|
+
}
|
|
35355
35400
|
return () => {
|
|
35356
|
-
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
35357
35401
|
(isArrayField ?
|
|
35358
|
-
_shouldUnregisterField && !control.
|
|
35402
|
+
_shouldUnregisterField && !control._state.action :
|
|
35359
35403
|
_shouldUnregisterField) ?
|
|
35360
35404
|
control.unregister(name) :
|
|
35361
35405
|
updateMounted(name, false);
|
|
35362
35406
|
};
|
|
35363
35407
|
}, [name, control, isArrayField, shouldUnregister]);
|
|
35408
|
+
React__default["default"].useEffect(() => {
|
|
35409
|
+
if (get(control._fields, name)) {
|
|
35410
|
+
control._updateDisabledField({
|
|
35411
|
+
disabled,
|
|
35412
|
+
fields: control._fields,
|
|
35413
|
+
name,
|
|
35414
|
+
value: get(control._fields, name)._f.value });
|
|
35415
|
+
|
|
35416
|
+
}
|
|
35417
|
+
}, [disabled, name, control]);
|
|
35364
35418
|
return {
|
|
35365
35419
|
field: {
|
|
35366
35420
|
name,
|
|
35367
35421
|
value,
|
|
35368
|
-
|
|
35369
|
-
|
|
35370
|
-
|
|
35371
|
-
|
|
35372
|
-
|
|
35373
|
-
|
|
35374
|
-
|
|
35375
|
-
|
|
35376
|
-
|
|
35377
|
-
|
|
35378
|
-
|
|
35379
|
-
|
|
35380
|
-
|
|
35381
|
-
|
|
35382
|
-
|
|
35383
|
-
|
|
35384
|
-
|
|
35385
|
-
|
|
35386
|
-
ref: React__default["default"].useCallback((elm) => {
|
|
35422
|
+
...(isBoolean(disabled) || formState.disabled ?
|
|
35423
|
+
{ disabled: formState.disabled || disabled } :
|
|
35424
|
+
{}),
|
|
35425
|
+
onChange: React__default["default"].useCallback((event) => _registerProps.current.onChange({
|
|
35426
|
+
target: {
|
|
35427
|
+
value: getEventValue(event),
|
|
35428
|
+
name: name },
|
|
35429
|
+
|
|
35430
|
+
type: EVENTS.CHANGE }),
|
|
35431
|
+
[name]),
|
|
35432
|
+
onBlur: React__default["default"].useCallback(() => _registerProps.current.onBlur({
|
|
35433
|
+
target: {
|
|
35434
|
+
value: get(control._formValues, name),
|
|
35435
|
+
name: name },
|
|
35436
|
+
|
|
35437
|
+
type: EVENTS.BLUR }),
|
|
35438
|
+
[name, control]),
|
|
35439
|
+
ref: (elm) => {
|
|
35387
35440
|
const field = get(control._fields, name);
|
|
35388
|
-
if (
|
|
35441
|
+
if (field && elm) {
|
|
35389
35442
|
field._f.ref = {
|
|
35390
35443
|
focus: () => elm.focus(),
|
|
35391
35444
|
select: () => elm.select(),
|
|
@@ -35393,67 +35446,75 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35393
35446
|
reportValidity: () => elm.reportValidity() };
|
|
35394
35447
|
|
|
35395
35448
|
}
|
|
35396
|
-
}
|
|
35449
|
+
} },
|
|
35397
35450
|
|
|
35398
35451
|
formState,
|
|
35399
35452
|
fieldState: Object.defineProperties({}, {
|
|
35400
35453
|
invalid: {
|
|
35454
|
+
enumerable: true,
|
|
35401
35455
|
get: () => !!get(formState.errors, name) },
|
|
35402
35456
|
|
|
35403
35457
|
isDirty: {
|
|
35458
|
+
enumerable: true,
|
|
35404
35459
|
get: () => !!get(formState.dirtyFields, name) },
|
|
35405
35460
|
|
|
35406
35461
|
isTouched: {
|
|
35462
|
+
enumerable: true,
|
|
35407
35463
|
get: () => !!get(formState.touchedFields, name) },
|
|
35408
35464
|
|
|
35465
|
+
isValidating: {
|
|
35466
|
+
enumerable: true,
|
|
35467
|
+
get: () => !!get(formState.validatingFields, name) },
|
|
35468
|
+
|
|
35409
35469
|
error: {
|
|
35470
|
+
enumerable: true,
|
|
35410
35471
|
get: () => get(formState.errors, name) } }) };
|
|
35411
35472
|
|
|
35412
35473
|
|
|
35413
35474
|
|
|
35414
35475
|
}
|
|
35415
35476
|
|
|
35416
|
-
/**
|
|
35417
|
-
* Component based on `useController` hook to work with controlled component.
|
|
35418
|
-
*
|
|
35419
|
-
* @remarks
|
|
35420
|
-
* [API](https://react-hook-form.com/
|
|
35421
|
-
*
|
|
35422
|
-
* @param props - the path name to the form field value, and validation rules.
|
|
35423
|
-
*
|
|
35424
|
-
* @returns provide field handler functions, field and form state.
|
|
35425
|
-
*
|
|
35426
|
-
* @example
|
|
35427
|
-
* ```tsx
|
|
35428
|
-
* function App() {
|
|
35429
|
-
* const { control } = useForm<FormValues>({
|
|
35430
|
-
* defaultValues: {
|
|
35431
|
-
* test: ""
|
|
35432
|
-
* }
|
|
35433
|
-
* });
|
|
35434
|
-
*
|
|
35435
|
-
* return (
|
|
35436
|
-
* <form>
|
|
35437
|
-
* <Controller
|
|
35438
|
-
* control={control}
|
|
35439
|
-
* name="test"
|
|
35440
|
-
* render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
|
|
35441
|
-
* <>
|
|
35442
|
-
* <input
|
|
35443
|
-
* onChange={onChange} // send value to hook form
|
|
35444
|
-
* onBlur={onBlur} // notify when input is touched
|
|
35445
|
-
* value={value} // return updated value
|
|
35446
|
-
* ref={ref} // set ref for focus management
|
|
35447
|
-
* />
|
|
35448
|
-
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
35449
|
-
* <p>{fieldState.isTouched ? "touched" : ""}</p>
|
|
35450
|
-
* </>
|
|
35451
|
-
* )}
|
|
35452
|
-
* />
|
|
35453
|
-
* </form>
|
|
35454
|
-
* );
|
|
35455
|
-
* }
|
|
35456
|
-
* ```
|
|
35477
|
+
/**
|
|
35478
|
+
* Component based on `useController` hook to work with controlled component.
|
|
35479
|
+
*
|
|
35480
|
+
* @remarks
|
|
35481
|
+
* [API](https://react-hook-form.com/docs/usecontroller/controller) • [Demo](https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw) • [Video](https://www.youtube.com/watch?v=N2UNk_UCVyA)
|
|
35482
|
+
*
|
|
35483
|
+
* @param props - the path name to the form field value, and validation rules.
|
|
35484
|
+
*
|
|
35485
|
+
* @returns provide field handler functions, field and form state.
|
|
35486
|
+
*
|
|
35487
|
+
* @example
|
|
35488
|
+
* ```tsx
|
|
35489
|
+
* function App() {
|
|
35490
|
+
* const { control } = useForm<FormValues>({
|
|
35491
|
+
* defaultValues: {
|
|
35492
|
+
* test: ""
|
|
35493
|
+
* }
|
|
35494
|
+
* });
|
|
35495
|
+
*
|
|
35496
|
+
* return (
|
|
35497
|
+
* <form>
|
|
35498
|
+
* <Controller
|
|
35499
|
+
* control={control}
|
|
35500
|
+
* name="test"
|
|
35501
|
+
* render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
|
|
35502
|
+
* <>
|
|
35503
|
+
* <input
|
|
35504
|
+
* onChange={onChange} // send value to hook form
|
|
35505
|
+
* onBlur={onBlur} // notify when input is touched
|
|
35506
|
+
* value={value} // return updated value
|
|
35507
|
+
* ref={ref} // set ref for focus management
|
|
35508
|
+
* />
|
|
35509
|
+
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
35510
|
+
* <p>{fieldState.isTouched ? "touched" : ""}</p>
|
|
35511
|
+
* </>
|
|
35512
|
+
* )}
|
|
35513
|
+
* />
|
|
35514
|
+
* </form>
|
|
35515
|
+
* );
|
|
35516
|
+
* }
|
|
35517
|
+
* ```
|
|
35457
35518
|
*/
|
|
35458
35519
|
const Controller = (props) => props.render(useController(props));
|
|
35459
35520
|
|
|
@@ -35467,72 +35528,64 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35467
35528
|
|
|
35468
35529
|
{};
|
|
35469
35530
|
|
|
35470
|
-
var
|
|
35531
|
+
var getValidationModes = (mode) => ({
|
|
35532
|
+
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
|
|
35533
|
+
isOnBlur: mode === VALIDATION_MODE.onBlur,
|
|
35534
|
+
isOnChange: mode === VALIDATION_MODE.onChange,
|
|
35535
|
+
isOnAll: mode === VALIDATION_MODE.all,
|
|
35536
|
+
isOnTouch: mode === VALIDATION_MODE.onTouched });
|
|
35471
35537
|
|
|
35472
|
-
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
|
35473
35538
|
|
|
35474
|
-
|
|
35475
|
-
|
|
35476
|
-
|
|
35477
|
-
|
|
35478
|
-
|
|
35479
|
-
while (++index < length) {
|
|
35480
|
-
const key = tempPath[index];
|
|
35481
|
-
let newValue = value;
|
|
35482
|
-
if (index !== lastIndex) {
|
|
35483
|
-
const objValue = object[key];
|
|
35484
|
-
newValue =
|
|
35485
|
-
isObject(objValue) || Array.isArray(objValue) ?
|
|
35486
|
-
objValue :
|
|
35487
|
-
!isNaN(+tempPath[index + 1]) ?
|
|
35488
|
-
[] :
|
|
35489
|
-
{};
|
|
35490
|
-
}
|
|
35491
|
-
object[key] = newValue;
|
|
35492
|
-
object = object[key];
|
|
35493
|
-
}
|
|
35494
|
-
return object;
|
|
35495
|
-
}
|
|
35539
|
+
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent && (
|
|
35540
|
+
_names.watchAll ||
|
|
35541
|
+
_names.watch.has(name) ||
|
|
35542
|
+
[..._names.watch].some((watchName) => name.startsWith(watchName) &&
|
|
35543
|
+
/^\.\w+/.test(name.slice(watchName.length))));
|
|
35496
35544
|
|
|
35497
|
-
const
|
|
35545
|
+
const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
|
35498
35546
|
for (const key of fieldsNames || Object.keys(fields)) {
|
|
35499
35547
|
const field = get(fields, key);
|
|
35500
35548
|
if (field) {
|
|
35501
35549
|
const { _f, ...currentField } = field;
|
|
35502
|
-
if (_f
|
|
35503
|
-
if (_f.
|
|
35550
|
+
if (_f) {
|
|
35551
|
+
if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
|
|
35504
35552
|
break;
|
|
35505
35553
|
} else
|
|
35506
|
-
if (_f.
|
|
35507
|
-
_f.refs[0].focus();
|
|
35554
|
+
if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
|
|
35508
35555
|
break;
|
|
35556
|
+
} else
|
|
35557
|
+
{
|
|
35558
|
+
iterateFieldsByAction(currentField, action);
|
|
35509
35559
|
}
|
|
35510
35560
|
} else
|
|
35511
35561
|
if (isObject(currentField)) {
|
|
35512
|
-
|
|
35562
|
+
iterateFieldsByAction(currentField, action);
|
|
35513
35563
|
}
|
|
35514
35564
|
}
|
|
35515
35565
|
}
|
|
35516
35566
|
};
|
|
35517
35567
|
|
|
35518
|
-
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent && (
|
|
35519
|
-
_names.watchAll ||
|
|
35520
|
-
_names.watch.has(name) ||
|
|
35521
|
-
[..._names.watch].some((watchName) => name.startsWith(watchName) &&
|
|
35522
|
-
/^\.\w+/.test(name.slice(watchName.length))));
|
|
35523
|
-
|
|
35524
35568
|
var updateFieldArrayRootError = (errors, error, name) => {
|
|
35525
|
-
const fieldArrayErrors =
|
|
35569
|
+
const fieldArrayErrors = convertToArrayPayload(get(errors, name));
|
|
35526
35570
|
set(fieldArrayErrors, 'root', error[name]);
|
|
35527
35571
|
set(errors, name, fieldArrayErrors);
|
|
35528
35572
|
return errors;
|
|
35529
35573
|
};
|
|
35530
35574
|
|
|
35531
|
-
var isBoolean = (value) => typeof value === 'boolean';
|
|
35532
|
-
|
|
35533
35575
|
var isFileInput = (element) => element.type === 'file';
|
|
35534
35576
|
|
|
35535
|
-
var
|
|
35577
|
+
var isFunction = (value) => typeof value === 'function';
|
|
35578
|
+
|
|
35579
|
+
var isHTMLElement = (value) => {
|
|
35580
|
+
if (!isWeb) {
|
|
35581
|
+
return false;
|
|
35582
|
+
}
|
|
35583
|
+
const owner = value ? value.ownerDocument : 0;
|
|
35584
|
+
return value instanceof (
|
|
35585
|
+
owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement);
|
|
35586
|
+
};
|
|
35587
|
+
|
|
35588
|
+
var isMessage = (value) => isString(value);
|
|
35536
35589
|
|
|
35537
35590
|
var isRadioInput = (element) => element.type === 'radio';
|
|
35538
35591
|
|
|
@@ -35595,15 +35648,16 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35595
35648
|
message: '' };
|
|
35596
35649
|
|
|
35597
35650
|
|
|
35598
|
-
var validateField = async (field,
|
|
35651
|
+
var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
|
|
35599
35652
|
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled } = field._f;
|
|
35653
|
+
const inputValue = get(formValues, name);
|
|
35600
35654
|
if (!mount || disabled) {
|
|
35601
35655
|
return {};
|
|
35602
35656
|
}
|
|
35603
35657
|
const inputRef = refs ? refs[0] : ref;
|
|
35604
35658
|
const setCustomValidity = (message) => {
|
|
35605
35659
|
if (shouldUseNativeValidation && inputRef.reportValidity) {
|
|
35606
|
-
inputRef.setCustomValidity(isBoolean(message) ? '' : message || '
|
|
35660
|
+
inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
|
|
35607
35661
|
inputRef.reportValidity();
|
|
35608
35662
|
}
|
|
35609
35663
|
};
|
|
@@ -35611,7 +35665,10 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35611
35665
|
const isRadio = isRadioInput(ref);
|
|
35612
35666
|
const isCheckBox = isCheckBoxInput(ref);
|
|
35613
35667
|
const isRadioOrCheckbox = isRadio || isCheckBox;
|
|
35614
|
-
const isEmpty = (valueAsNumber || isFileInput(ref)) &&
|
|
35668
|
+
const isEmpty = (valueAsNumber || isFileInput(ref)) &&
|
|
35669
|
+
isUndefined(ref.value) &&
|
|
35670
|
+
isUndefined(inputValue) ||
|
|
35671
|
+
isHTMLElement(ref) && ref.value === '' ||
|
|
35615
35672
|
inputValue === '' ||
|
|
35616
35673
|
Array.isArray(inputValue) && !inputValue.length;
|
|
35617
35674
|
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
|
@@ -35653,7 +35710,8 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35653
35710
|
const maxOutput = getValueAndMessage(max);
|
|
35654
35711
|
const minOutput = getValueAndMessage(min);
|
|
35655
35712
|
if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
|
|
35656
|
-
const valueNumber = ref.valueAsNumber ||
|
|
35713
|
+
const valueNumber = ref.valueAsNumber || (
|
|
35714
|
+
inputValue ? +inputValue : inputValue);
|
|
35657
35715
|
if (!isNullOrUndefined(maxOutput.value)) {
|
|
35658
35716
|
exceedMax = valueNumber > maxOutput.value;
|
|
35659
35717
|
}
|
|
@@ -35663,11 +35721,22 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35663
35721
|
} else
|
|
35664
35722
|
{
|
|
35665
35723
|
const valueDate = ref.valueAsDate || new Date(inputValue);
|
|
35666
|
-
|
|
35667
|
-
|
|
35668
|
-
|
|
35669
|
-
if (isString(
|
|
35670
|
-
|
|
35724
|
+
const convertTimeToDate = (time) => new Date(new Date().toDateString() + ' ' + time);
|
|
35725
|
+
const isTime = ref.type == 'time';
|
|
35726
|
+
const isWeek = ref.type == 'week';
|
|
35727
|
+
if (isString(maxOutput.value) && inputValue) {
|
|
35728
|
+
exceedMax = isTime ?
|
|
35729
|
+
convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value) :
|
|
35730
|
+
isWeek ?
|
|
35731
|
+
inputValue > maxOutput.value :
|
|
35732
|
+
valueDate > new Date(maxOutput.value);
|
|
35733
|
+
}
|
|
35734
|
+
if (isString(minOutput.value) && inputValue) {
|
|
35735
|
+
exceedMin = isTime ?
|
|
35736
|
+
convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value) :
|
|
35737
|
+
isWeek ?
|
|
35738
|
+
inputValue < minOutput.value :
|
|
35739
|
+
valueDate < new Date(minOutput.value);
|
|
35671
35740
|
}
|
|
35672
35741
|
}
|
|
35673
35742
|
if (exceedMax || exceedMin) {
|
|
@@ -35684,9 +35753,9 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35684
35753
|
const maxLengthOutput = getValueAndMessage(maxLength);
|
|
35685
35754
|
const minLengthOutput = getValueAndMessage(minLength);
|
|
35686
35755
|
const exceedMax = !isNullOrUndefined(maxLengthOutput.value) &&
|
|
35687
|
-
inputValue.length > maxLengthOutput.value;
|
|
35756
|
+
inputValue.length > +maxLengthOutput.value;
|
|
35688
35757
|
const exceedMin = !isNullOrUndefined(minLengthOutput.value) &&
|
|
35689
|
-
inputValue.length < minLengthOutput.value;
|
|
35758
|
+
inputValue.length < +minLengthOutput.value;
|
|
35690
35759
|
if (exceedMax || exceedMin) {
|
|
35691
35760
|
getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
|
|
35692
35761
|
if (!validateAllFieldCriteria) {
|
|
@@ -35712,7 +35781,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35712
35781
|
}
|
|
35713
35782
|
if (validate) {
|
|
35714
35783
|
if (isFunction(validate)) {
|
|
35715
|
-
const result = await validate(inputValue);
|
|
35784
|
+
const result = await validate(inputValue, formValues);
|
|
35716
35785
|
const validateError = getValidateError(result, inputRef);
|
|
35717
35786
|
if (validateError) {
|
|
35718
35787
|
error[name] = {
|
|
@@ -35731,7 +35800,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35731
35800
|
if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
|
|
35732
35801
|
break;
|
|
35733
35802
|
}
|
|
35734
|
-
const validateError = getValidateError(await validate[key](inputValue), inputRef, key);
|
|
35803
|
+
const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
|
|
35735
35804
|
if (validateError) {
|
|
35736
35805
|
validationResult = {
|
|
35737
35806
|
...validateError,
|
|
@@ -35758,43 +35827,6 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35758
35827
|
return error;
|
|
35759
35828
|
};
|
|
35760
35829
|
|
|
35761
|
-
var isWeb = typeof window !== 'undefined' &&
|
|
35762
|
-
typeof window.HTMLElement !== 'undefined' &&
|
|
35763
|
-
typeof document !== 'undefined';
|
|
35764
|
-
|
|
35765
|
-
function cloneObject(data) {
|
|
35766
|
-
let copy;
|
|
35767
|
-
const isArray = Array.isArray(data);
|
|
35768
|
-
if (data instanceof Date) {
|
|
35769
|
-
copy = new Date(data);
|
|
35770
|
-
} else
|
|
35771
|
-
if (data instanceof Set) {
|
|
35772
|
-
copy = new Set(data);
|
|
35773
|
-
} else
|
|
35774
|
-
if (!(isWeb && (data instanceof Blob || data instanceof FileList)) && (
|
|
35775
|
-
isArray || isObject(data))) {
|
|
35776
|
-
copy = isArray ? [] : {};
|
|
35777
|
-
for (const key in data) {
|
|
35778
|
-
if (isFunction(data[key])) {
|
|
35779
|
-
copy = data;
|
|
35780
|
-
break;
|
|
35781
|
-
}
|
|
35782
|
-
copy[key] = cloneObject(data[key]);
|
|
35783
|
-
}
|
|
35784
|
-
} else
|
|
35785
|
-
{
|
|
35786
|
-
return data;
|
|
35787
|
-
}
|
|
35788
|
-
return copy;
|
|
35789
|
-
}
|
|
35790
|
-
|
|
35791
|
-
var getValidationModes = (mode) => ({
|
|
35792
|
-
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
|
|
35793
|
-
isOnBlur: mode === VALIDATION_MODE.onBlur,
|
|
35794
|
-
isOnChange: mode === VALIDATION_MODE.onChange,
|
|
35795
|
-
isOnAll: mode === VALIDATION_MODE.all,
|
|
35796
|
-
isOnTouch: mode === VALIDATION_MODE.onTouched });
|
|
35797
|
-
|
|
35798
35830
|
function baseGet(object, updatePath) {
|
|
35799
35831
|
const length = updatePath.slice(0, -1).length;
|
|
35800
35832
|
let index = 0;
|
|
@@ -35805,47 +35837,37 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35805
35837
|
}
|
|
35806
35838
|
function isEmptyArray(obj) {
|
|
35807
35839
|
for (const key in obj) {
|
|
35808
|
-
if (!isUndefined(obj[key])) {
|
|
35840
|
+
if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
|
|
35809
35841
|
return false;
|
|
35810
35842
|
}
|
|
35811
35843
|
}
|
|
35812
35844
|
return true;
|
|
35813
35845
|
}
|
|
35814
35846
|
function unset(object, path) {
|
|
35815
|
-
const
|
|
35816
|
-
|
|
35817
|
-
|
|
35818
|
-
|
|
35847
|
+
const paths = Array.isArray(path) ?
|
|
35848
|
+
path :
|
|
35849
|
+
isKey(path) ?
|
|
35850
|
+
[path] :
|
|
35851
|
+
stringToPath(path);
|
|
35852
|
+
const childObject = paths.length === 1 ? object : baseGet(object, paths);
|
|
35853
|
+
const index = paths.length - 1;
|
|
35854
|
+
const key = paths[index];
|
|
35819
35855
|
if (childObject) {
|
|
35820
35856
|
delete childObject[key];
|
|
35821
35857
|
}
|
|
35822
|
-
|
|
35823
|
-
|
|
35824
|
-
|
|
35825
|
-
|
|
35826
|
-
const currentPathsLength = currentPaths.length - 1;
|
|
35827
|
-
if (k > 0) {
|
|
35828
|
-
previousObjRef = object;
|
|
35829
|
-
}
|
|
35830
|
-
while (++index < currentPaths.length) {
|
|
35831
|
-
const item = currentPaths[index];
|
|
35832
|
-
objectRef = objectRef ? objectRef[item] : object[item];
|
|
35833
|
-
if (currentPathsLength === index && (
|
|
35834
|
-
isObject(objectRef) && isEmptyObject(objectRef) ||
|
|
35835
|
-
Array.isArray(objectRef) && isEmptyArray(objectRef))) {
|
|
35836
|
-
previousObjRef ? delete previousObjRef[item] : delete object[item];
|
|
35837
|
-
}
|
|
35838
|
-
previousObjRef = objectRef;
|
|
35839
|
-
}
|
|
35858
|
+
if (index !== 0 && (
|
|
35859
|
+
isObject(childObject) && isEmptyObject(childObject) ||
|
|
35860
|
+
Array.isArray(childObject) && isEmptyArray(childObject))) {
|
|
35861
|
+
unset(object, paths.slice(0, -1));
|
|
35840
35862
|
}
|
|
35841
35863
|
return object;
|
|
35842
35864
|
}
|
|
35843
35865
|
|
|
35844
|
-
|
|
35866
|
+
var createSubject = () => {
|
|
35845
35867
|
let _observers = [];
|
|
35846
35868
|
const next = (value) => {
|
|
35847
35869
|
for (const observer of _observers) {
|
|
35848
|
-
observer.next(value);
|
|
35870
|
+
observer.next && observer.next(value);
|
|
35849
35871
|
}
|
|
35850
35872
|
};
|
|
35851
35873
|
const subscribe = (observer) => {
|
|
@@ -35867,7 +35889,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35867
35889
|
subscribe,
|
|
35868
35890
|
unsubscribe };
|
|
35869
35891
|
|
|
35870
|
-
}
|
|
35892
|
+
};
|
|
35871
35893
|
|
|
35872
35894
|
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
35873
35895
|
|
|
@@ -35902,18 +35924,21 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35902
35924
|
return true;
|
|
35903
35925
|
}
|
|
35904
35926
|
|
|
35905
|
-
var isHTMLElement = (value) => {
|
|
35906
|
-
const owner = value ? value.ownerDocument : 0;
|
|
35907
|
-
const ElementClass = owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement;
|
|
35908
|
-
return value instanceof ElementClass;
|
|
35909
|
-
};
|
|
35910
|
-
|
|
35911
35927
|
var isMultipleSelect = (element) => element.type === `select-multiple`;
|
|
35912
35928
|
|
|
35913
35929
|
var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
|
|
35914
35930
|
|
|
35915
35931
|
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
|
|
35916
35932
|
|
|
35933
|
+
var objectHasFunction = (data) => {
|
|
35934
|
+
for (const key in data) {
|
|
35935
|
+
if (isFunction(data[key])) {
|
|
35936
|
+
return true;
|
|
35937
|
+
}
|
|
35938
|
+
}
|
|
35939
|
+
return false;
|
|
35940
|
+
};
|
|
35941
|
+
|
|
35917
35942
|
function markFieldsDirty(data, fields = {}) {
|
|
35918
35943
|
const isParentNodeArray = Array.isArray(data);
|
|
35919
35944
|
if (isObject(data) || isParentNodeArray) {
|
|
@@ -35958,9 +35983,11 @@ Check the top-level render call using <` + t + ">.");
|
|
|
35958
35983
|
var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value) ?
|
|
35959
35984
|
value :
|
|
35960
35985
|
valueAsNumber ?
|
|
35961
|
-
value === ''
|
|
35986
|
+
value === '' ?
|
|
35962
35987
|
NaN :
|
|
35988
|
+
value ?
|
|
35963
35989
|
+value :
|
|
35990
|
+
value :
|
|
35964
35991
|
valueAsDate && isString(value) ?
|
|
35965
35992
|
new Date(value) :
|
|
35966
35993
|
setValueAs ?
|
|
@@ -36002,7 +36029,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36002
36029
|
};
|
|
36003
36030
|
|
|
36004
36031
|
var getRuleValue = (rule) => isUndefined(rule) ?
|
|
36005
|
-
|
|
36032
|
+
rule :
|
|
36006
36033
|
isRegex(rule) ?
|
|
36007
36034
|
rule.source :
|
|
36008
36035
|
isObject(rule) ?
|
|
@@ -36078,23 +36105,28 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36078
36105
|
...props };
|
|
36079
36106
|
|
|
36080
36107
|
let _formState = {
|
|
36108
|
+
submitCount: 0,
|
|
36081
36109
|
isDirty: false,
|
|
36110
|
+
isLoading: isFunction(_options.defaultValues),
|
|
36082
36111
|
isValidating: false,
|
|
36083
|
-
dirtyFields: {},
|
|
36084
36112
|
isSubmitted: false,
|
|
36085
|
-
submitCount: 0,
|
|
36086
|
-
touchedFields: {},
|
|
36087
36113
|
isSubmitting: false,
|
|
36088
36114
|
isSubmitSuccessful: false,
|
|
36089
36115
|
isValid: false,
|
|
36090
|
-
|
|
36116
|
+
touchedFields: {},
|
|
36117
|
+
dirtyFields: {},
|
|
36118
|
+
validatingFields: {},
|
|
36119
|
+
errors: _options.errors || {},
|
|
36120
|
+
disabled: _options.disabled || false };
|
|
36091
36121
|
|
|
36092
36122
|
let _fields = {};
|
|
36093
|
-
let _defaultValues =
|
|
36123
|
+
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values) ?
|
|
36124
|
+
cloneObject(_options.defaultValues || _options.values) || {} :
|
|
36125
|
+
{};
|
|
36094
36126
|
let _formValues = _options.shouldUnregister ?
|
|
36095
36127
|
{} :
|
|
36096
36128
|
cloneObject(_defaultValues);
|
|
36097
|
-
let
|
|
36129
|
+
let _state = {
|
|
36098
36130
|
action: false,
|
|
36099
36131
|
mount: false,
|
|
36100
36132
|
watch: false };
|
|
@@ -36107,17 +36139,17 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36107
36139
|
|
|
36108
36140
|
let delayErrorCallback;
|
|
36109
36141
|
let timer = 0;
|
|
36110
|
-
let validateFields = {};
|
|
36111
36142
|
const _proxyFormState = {
|
|
36112
36143
|
isDirty: false,
|
|
36113
36144
|
dirtyFields: false,
|
|
36145
|
+
validatingFields: false,
|
|
36114
36146
|
touchedFields: false,
|
|
36115
36147
|
isValidating: false,
|
|
36116
36148
|
isValid: false,
|
|
36117
36149
|
errors: false };
|
|
36118
36150
|
|
|
36119
36151
|
const _subjects = {
|
|
36120
|
-
|
|
36152
|
+
values: createSubject(),
|
|
36121
36153
|
array: createSubject(),
|
|
36122
36154
|
state: createSubject() };
|
|
36123
36155
|
|
|
@@ -36126,32 +36158,43 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36126
36158
|
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
|
36127
36159
|
const debounce = (callback) => (wait) => {
|
|
36128
36160
|
clearTimeout(timer);
|
|
36129
|
-
timer =
|
|
36161
|
+
timer = setTimeout(callback, wait);
|
|
36130
36162
|
};
|
|
36131
|
-
const _updateValid = async (
|
|
36132
|
-
|
|
36133
|
-
|
|
36134
|
-
isValid = _options.resolver ?
|
|
36163
|
+
const _updateValid = async (shouldUpdateValid) => {
|
|
36164
|
+
if (_proxyFormState.isValid || shouldUpdateValid) {
|
|
36165
|
+
const isValid = _options.resolver ?
|
|
36135
36166
|
isEmptyObject((await _executeSchema()).errors) :
|
|
36136
36167
|
await executeBuiltInValidation(_fields, true);
|
|
36137
|
-
if (
|
|
36138
|
-
_formState.isValid = isValid;
|
|
36168
|
+
if (isValid !== _formState.isValid) {
|
|
36139
36169
|
_subjects.state.next({
|
|
36140
36170
|
isValid });
|
|
36141
36171
|
|
|
36142
36172
|
}
|
|
36143
36173
|
}
|
|
36144
|
-
|
|
36174
|
+
};
|
|
36175
|
+
const _updateIsValidating = (names, isValidating) => {
|
|
36176
|
+
if (_proxyFormState.isValidating || _proxyFormState.validatingFields) {
|
|
36177
|
+
(names || Array.from(_names.mount)).forEach((name) => {
|
|
36178
|
+
if (name) {
|
|
36179
|
+
isValidating ?
|
|
36180
|
+
set(_formState.validatingFields, name, isValidating) :
|
|
36181
|
+
unset(_formState.validatingFields, name);
|
|
36182
|
+
}
|
|
36183
|
+
});
|
|
36184
|
+
_subjects.state.next({
|
|
36185
|
+
validatingFields: _formState.validatingFields,
|
|
36186
|
+
isValidating: !isEmptyObject(_formState.validatingFields) });
|
|
36187
|
+
|
|
36188
|
+
}
|
|
36145
36189
|
};
|
|
36146
36190
|
const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
|
|
36147
36191
|
if (args && method) {
|
|
36148
|
-
|
|
36192
|
+
_state.action = true;
|
|
36149
36193
|
if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
|
|
36150
36194
|
const fieldValues = method(get(_fields, name), args.argA, args.argB);
|
|
36151
36195
|
shouldSetValues && set(_fields, name, fieldValues);
|
|
36152
36196
|
}
|
|
36153
|
-
if (
|
|
36154
|
-
shouldUpdateFieldsAndState &&
|
|
36197
|
+
if (shouldUpdateFieldsAndState &&
|
|
36155
36198
|
Array.isArray(get(_formState.errors, name))) {
|
|
36156
36199
|
const errors = method(get(_formState.errors, name), args.argA, args.argB);
|
|
36157
36200
|
shouldSetValues && set(_formState.errors, name, errors);
|
|
@@ -36167,6 +36210,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36167
36210
|
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
|
36168
36211
|
}
|
|
36169
36212
|
_subjects.state.next({
|
|
36213
|
+
name,
|
|
36170
36214
|
isDirty: _getDirty(name, values),
|
|
36171
36215
|
dirtyFields: _formState.dirtyFields,
|
|
36172
36216
|
errors: _formState.errors,
|
|
@@ -36182,6 +36226,13 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36182
36226
|
_subjects.state.next({
|
|
36183
36227
|
errors: _formState.errors });
|
|
36184
36228
|
|
|
36229
|
+
};
|
|
36230
|
+
const _setErrors = (errors) => {
|
|
36231
|
+
_formState.errors = errors;
|
|
36232
|
+
_subjects.state.next({
|
|
36233
|
+
errors: _formState.errors,
|
|
36234
|
+
isValid: false });
|
|
36235
|
+
|
|
36185
36236
|
};
|
|
36186
36237
|
const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
|
|
36187
36238
|
const field = get(_fields, name);
|
|
@@ -36192,45 +36243,54 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36192
36243
|
shouldSkipSetValueAs ?
|
|
36193
36244
|
set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f)) :
|
|
36194
36245
|
setFieldValue(name, defaultValue);
|
|
36195
|
-
|
|
36246
|
+
_state.mount && _updateValid();
|
|
36196
36247
|
}
|
|
36197
36248
|
};
|
|
36198
36249
|
const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
|
|
36199
|
-
let
|
|
36250
|
+
let shouldUpdateField = false;
|
|
36251
|
+
let isPreviousDirty = false;
|
|
36200
36252
|
const output = {
|
|
36201
36253
|
name };
|
|
36202
36254
|
|
|
36203
|
-
const
|
|
36204
|
-
|
|
36205
|
-
|
|
36206
|
-
|
|
36207
|
-
|
|
36208
|
-
|
|
36209
|
-
|
|
36210
|
-
|
|
36211
|
-
|
|
36212
|
-
isCurrentFieldPristine
|
|
36255
|
+
const disabledField = !!(get(_fields, name) &&
|
|
36256
|
+
get(_fields, name)._f &&
|
|
36257
|
+
get(_fields, name)._f.disabled);
|
|
36258
|
+
if (!isBlurEvent || shouldDirty) {
|
|
36259
|
+
if (_proxyFormState.isDirty) {
|
|
36260
|
+
isPreviousDirty = _formState.isDirty;
|
|
36261
|
+
_formState.isDirty = output.isDirty = _getDirty();
|
|
36262
|
+
shouldUpdateField = isPreviousDirty !== output.isDirty;
|
|
36263
|
+
}
|
|
36264
|
+
const isCurrentFieldPristine = disabledField || deepEqual(get(_defaultValues, name), fieldValue);
|
|
36265
|
+
isPreviousDirty = !!(!disabledField && get(_formState.dirtyFields, name));
|
|
36266
|
+
isCurrentFieldPristine || disabledField ?
|
|
36213
36267
|
unset(_formState.dirtyFields, name) :
|
|
36214
36268
|
set(_formState.dirtyFields, name, true);
|
|
36215
36269
|
output.dirtyFields = _formState.dirtyFields;
|
|
36216
|
-
|
|
36217
|
-
|
|
36218
|
-
|
|
36219
|
-
|
|
36220
|
-
|
|
36221
|
-
|
|
36222
|
-
|
|
36223
|
-
|
|
36224
|
-
|
|
36225
|
-
|
|
36226
|
-
|
|
36227
|
-
|
|
36228
|
-
|
|
36229
|
-
|
|
36270
|
+
shouldUpdateField =
|
|
36271
|
+
shouldUpdateField ||
|
|
36272
|
+
_proxyFormState.dirtyFields &&
|
|
36273
|
+
isPreviousDirty !== !isCurrentFieldPristine;
|
|
36274
|
+
}
|
|
36275
|
+
if (isBlurEvent) {
|
|
36276
|
+
const isPreviousFieldTouched = get(_formState.touchedFields, name);
|
|
36277
|
+
if (!isPreviousFieldTouched) {
|
|
36278
|
+
set(_formState.touchedFields, name, isBlurEvent);
|
|
36279
|
+
output.touchedFields = _formState.touchedFields;
|
|
36280
|
+
shouldUpdateField =
|
|
36281
|
+
shouldUpdateField ||
|
|
36282
|
+
_proxyFormState.touchedFields &&
|
|
36283
|
+
isPreviousFieldTouched !== isBlurEvent;
|
|
36284
|
+
}
|
|
36285
|
+
}
|
|
36286
|
+
shouldUpdateField && shouldRender && _subjects.state.next(output);
|
|
36287
|
+
return shouldUpdateField ? output : {};
|
|
36230
36288
|
};
|
|
36231
|
-
const shouldRenderByError =
|
|
36289
|
+
const shouldRenderByError = (name, isValid, error, fieldState) => {
|
|
36232
36290
|
const previousFieldError = get(_formState.errors, name);
|
|
36233
|
-
const shouldUpdateValid = _proxyFormState.isValid &&
|
|
36291
|
+
const shouldUpdateValid = _proxyFormState.isValid &&
|
|
36292
|
+
isBoolean(isValid) &&
|
|
36293
|
+
_formState.isValid !== isValid;
|
|
36234
36294
|
if (props.delayError && error) {
|
|
36235
36295
|
delayErrorCallback = debounce(() => updateErrors(name, error));
|
|
36236
36296
|
delayErrorCallback(props.delayError);
|
|
@@ -36247,7 +36307,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36247
36307
|
shouldUpdateValid) {
|
|
36248
36308
|
const updatedFormState = {
|
|
36249
36309
|
...fieldState,
|
|
36250
|
-
...(shouldUpdateValid ? { isValid } : {}),
|
|
36310
|
+
...(shouldUpdateValid && isBoolean(isValid) ? { isValid } : {}),
|
|
36251
36311
|
errors: _formState.errors,
|
|
36252
36312
|
name };
|
|
36253
36313
|
|
|
@@ -36257,20 +36317,15 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36257
36317
|
|
|
36258
36318
|
_subjects.state.next(updatedFormState);
|
|
36259
36319
|
}
|
|
36260
|
-
validateFields[name]--;
|
|
36261
|
-
if (_proxyFormState.isValidating &&
|
|
36262
|
-
!Object.values(validateFields).some((v) => v)) {
|
|
36263
|
-
_subjects.state.next({
|
|
36264
|
-
isValidating: false });
|
|
36265
|
-
|
|
36266
|
-
validateFields = {};
|
|
36267
|
-
}
|
|
36268
36320
|
};
|
|
36269
|
-
const _executeSchema = async (name) =>
|
|
36270
|
-
|
|
36271
|
-
|
|
36321
|
+
const _executeSchema = async (name) => {
|
|
36322
|
+
_updateIsValidating(name, true);
|
|
36323
|
+
const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
36324
|
+
_updateIsValidating(name);
|
|
36325
|
+
return result;
|
|
36326
|
+
};
|
|
36272
36327
|
const executeSchemaAndUpdateState = async (names) => {
|
|
36273
|
-
const { errors } = await _executeSchema();
|
|
36328
|
+
const { errors } = await _executeSchema(names);
|
|
36274
36329
|
if (names) {
|
|
36275
36330
|
for (const name of names) {
|
|
36276
36331
|
const error = get(errors, name);
|
|
@@ -36293,7 +36348,9 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36293
36348
|
const { _f, ...fieldValue } = field;
|
|
36294
36349
|
if (_f) {
|
|
36295
36350
|
const isFieldArrayRoot = _names.array.has(_f.name);
|
|
36296
|
-
|
|
36351
|
+
_updateIsValidating([name], true);
|
|
36352
|
+
const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
|
36353
|
+
_updateIsValidating([name]);
|
|
36297
36354
|
if (fieldError[_f.name]) {
|
|
36298
36355
|
context.valid = false;
|
|
36299
36356
|
if (shouldOnlyCheckValid) {
|
|
@@ -36326,19 +36383,16 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36326
36383
|
};
|
|
36327
36384
|
const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
|
|
36328
36385
|
!deepEqual(getValues(), _defaultValues));
|
|
36329
|
-
const _getWatch = (names, defaultValue, isGlobal) => {
|
|
36330
|
-
|
|
36331
|
-
|
|
36332
|
-
|
|
36333
|
-
|
|
36334
|
-
|
|
36335
|
-
|
|
36336
|
-
|
|
36337
|
-
|
|
36338
|
-
|
|
36339
|
-
return generateWatchOutput(names, _names, fieldValues, isGlobal);
|
|
36340
|
-
};
|
|
36341
|
-
const _getFieldArray = (name) => compact(get(_stateFlags.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
|
|
36386
|
+
const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
|
|
36387
|
+
...(_state.mount ?
|
|
36388
|
+
_formValues :
|
|
36389
|
+
isUndefined(defaultValue) ?
|
|
36390
|
+
_defaultValues :
|
|
36391
|
+
isString(names) ?
|
|
36392
|
+
{ [names]: defaultValue } :
|
|
36393
|
+
defaultValue) },
|
|
36394
|
+
isGlobal, defaultValue);
|
|
36395
|
+
const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
|
|
36342
36396
|
const setFieldValue = (name, value, options = {}) => {
|
|
36343
36397
|
const field = get(_fields, name);
|
|
36344
36398
|
let fieldValue = value;
|
|
@@ -36348,16 +36402,16 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36348
36402
|
!fieldReference.disabled &&
|
|
36349
36403
|
set(_formValues, name, getFieldValueAs(value, fieldReference));
|
|
36350
36404
|
fieldValue =
|
|
36351
|
-
|
|
36405
|
+
isHTMLElement(fieldReference.ref) && isNullOrUndefined(value) ?
|
|
36352
36406
|
'' :
|
|
36353
36407
|
value;
|
|
36354
36408
|
if (isMultipleSelect(fieldReference.ref)) {
|
|
36355
|
-
[...fieldReference.ref.options].forEach((
|
|
36409
|
+
[...fieldReference.ref.options].forEach((optionRef) => optionRef.selected = fieldValue.includes(optionRef.value));
|
|
36356
36410
|
} else
|
|
36357
36411
|
if (fieldReference.refs) {
|
|
36358
36412
|
if (isCheckBoxInput(fieldReference.ref)) {
|
|
36359
36413
|
fieldReference.refs.length > 1 ?
|
|
36360
|
-
fieldReference.refs.forEach((checkboxRef) => !checkboxRef.disabled && (
|
|
36414
|
+
fieldReference.refs.forEach((checkboxRef) => (!checkboxRef.defaultChecked || !checkboxRef.disabled) && (
|
|
36361
36415
|
checkboxRef.checked = Array.isArray(fieldValue) ?
|
|
36362
36416
|
!!fieldValue.find((data) => data === checkboxRef.value) :
|
|
36363
36417
|
fieldValue === checkboxRef.value)) :
|
|
@@ -36374,8 +36428,9 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36374
36428
|
{
|
|
36375
36429
|
fieldReference.ref.value = fieldValue;
|
|
36376
36430
|
if (!fieldReference.ref.type) {
|
|
36377
|
-
_subjects.
|
|
36378
|
-
name
|
|
36431
|
+
_subjects.values.next({
|
|
36432
|
+
name,
|
|
36433
|
+
values: { ..._formValues } });
|
|
36379
36434
|
|
|
36380
36435
|
}
|
|
36381
36436
|
}
|
|
@@ -36406,14 +36461,13 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36406
36461
|
if (isFieldArray) {
|
|
36407
36462
|
_subjects.array.next({
|
|
36408
36463
|
name,
|
|
36409
|
-
values: _formValues });
|
|
36464
|
+
values: { ..._formValues } });
|
|
36410
36465
|
|
|
36411
36466
|
if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
|
|
36412
36467
|
options.shouldDirty) {
|
|
36413
|
-
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
|
36414
36468
|
_subjects.state.next({
|
|
36415
36469
|
name,
|
|
36416
|
-
dirtyFields:
|
|
36470
|
+
dirtyFields: getDirtyFields(_defaultValues, _formValues),
|
|
36417
36471
|
isDirty: _getDirty(name, cloneValue) });
|
|
36418
36472
|
|
|
36419
36473
|
}
|
|
@@ -36423,21 +36477,28 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36423
36477
|
setValues(name, cloneValue, options) :
|
|
36424
36478
|
setFieldValue(name, cloneValue, options);
|
|
36425
36479
|
}
|
|
36426
|
-
isWatched(name, _names) && _subjects.state.next({});
|
|
36427
|
-
_subjects.
|
|
36428
|
-
name
|
|
36480
|
+
isWatched(name, _names) && _subjects.state.next({ ..._formState });
|
|
36481
|
+
_subjects.values.next({
|
|
36482
|
+
name: _state.mount ? name : undefined,
|
|
36483
|
+
values: { ..._formValues } });
|
|
36429
36484
|
|
|
36430
36485
|
};
|
|
36431
36486
|
const onChange = async (event) => {
|
|
36487
|
+
_state.mount = true;
|
|
36432
36488
|
const target = event.target;
|
|
36433
36489
|
let name = target.name;
|
|
36490
|
+
let isFieldValueUpdated = true;
|
|
36434
36491
|
const field = get(_fields, name);
|
|
36492
|
+
const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
|
|
36493
|
+
const _updateIsFieldValueUpdated = (fieldValue) => {
|
|
36494
|
+
isFieldValueUpdated =
|
|
36495
|
+
Number.isNaN(fieldValue) ||
|
|
36496
|
+
fieldValue === get(_formValues, name, fieldValue);
|
|
36497
|
+
};
|
|
36435
36498
|
if (field) {
|
|
36436
36499
|
let error;
|
|
36437
36500
|
let isValid;
|
|
36438
|
-
const fieldValue =
|
|
36439
|
-
getFieldValue(field._f) :
|
|
36440
|
-
getEventValue(event);
|
|
36501
|
+
const fieldValue = getCurrentFieldValue();
|
|
36441
36502
|
const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
|
|
36442
36503
|
const shouldSkipValidation = !hasValidation(field._f) &&
|
|
36443
36504
|
!_options.resolver &&
|
|
@@ -36456,43 +36517,60 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36456
36517
|
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
|
|
36457
36518
|
const shouldRender = !isEmptyObject(fieldState) || watched;
|
|
36458
36519
|
!isBlurEvent &&
|
|
36459
|
-
_subjects.
|
|
36520
|
+
_subjects.values.next({
|
|
36460
36521
|
name,
|
|
36461
|
-
type: event.type
|
|
36522
|
+
type: event.type,
|
|
36523
|
+
values: { ..._formValues } });
|
|
36462
36524
|
|
|
36463
36525
|
if (shouldSkipValidation) {
|
|
36526
|
+
_proxyFormState.isValid && _updateValid();
|
|
36464
36527
|
return shouldRender &&
|
|
36465
36528
|
_subjects.state.next({ name, ...(watched ? {} : fieldState) });
|
|
36466
36529
|
}
|
|
36467
|
-
!isBlurEvent && watched && _subjects.state.next({});
|
|
36468
|
-
validateFields[name] = validateFields[name] ? +1 : 1;
|
|
36469
|
-
_subjects.state.next({
|
|
36470
|
-
isValidating: true });
|
|
36471
|
-
|
|
36530
|
+
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
|
36472
36531
|
if (_options.resolver) {
|
|
36473
36532
|
const { errors } = await _executeSchema([name]);
|
|
36474
|
-
|
|
36475
|
-
|
|
36476
|
-
|
|
36477
|
-
|
|
36478
|
-
|
|
36533
|
+
_updateIsFieldValueUpdated(fieldValue);
|
|
36534
|
+
if (isFieldValueUpdated) {
|
|
36535
|
+
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
36536
|
+
const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
|
|
36537
|
+
error = errorLookupResult.error;
|
|
36538
|
+
name = errorLookupResult.name;
|
|
36539
|
+
isValid = isEmptyObject(errors);
|
|
36540
|
+
}
|
|
36479
36541
|
} else
|
|
36480
36542
|
{
|
|
36481
|
-
|
|
36482
|
-
|
|
36543
|
+
_updateIsValidating([name], true);
|
|
36544
|
+
error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
|
36545
|
+
_updateIsValidating([name]);
|
|
36546
|
+
_updateIsFieldValueUpdated(fieldValue);
|
|
36547
|
+
if (isFieldValueUpdated) {
|
|
36548
|
+
if (error) {
|
|
36549
|
+
isValid = false;
|
|
36550
|
+
} else
|
|
36551
|
+
if (_proxyFormState.isValid) {
|
|
36552
|
+
isValid = await executeBuiltInValidation(_fields, true);
|
|
36553
|
+
}
|
|
36554
|
+
}
|
|
36555
|
+
}
|
|
36556
|
+
if (isFieldValueUpdated) {
|
|
36557
|
+
field._f.deps &&
|
|
36558
|
+
trigger(field._f.deps);
|
|
36559
|
+
shouldRenderByError(name, isValid, error, fieldState);
|
|
36483
36560
|
}
|
|
36484
|
-
field._f.deps &&
|
|
36485
|
-
trigger(field._f.deps);
|
|
36486
|
-
shouldRenderByError(name, isValid, error, fieldState);
|
|
36487
36561
|
}
|
|
36488
36562
|
};
|
|
36563
|
+
const _focusInput = (ref, key) => {
|
|
36564
|
+
if (get(_formState.errors, key) && ref.focus) {
|
|
36565
|
+
ref.focus();
|
|
36566
|
+
return 1;
|
|
36567
|
+
}
|
|
36568
|
+
return;
|
|
36569
|
+
};
|
|
36489
36570
|
const trigger = async (name, options = {}) => {
|
|
36490
36571
|
let isValid;
|
|
36491
36572
|
let validationResult;
|
|
36492
36573
|
const fieldNames = convertToArrayPayload(name);
|
|
36493
|
-
_subjects.state.next({
|
|
36494
|
-
isValidating: true });
|
|
36495
|
-
|
|
36496
36574
|
if (_options.resolver) {
|
|
36497
36575
|
const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
|
|
36498
36576
|
isValid = isEmptyObject(errors);
|
|
@@ -36515,19 +36593,17 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36515
36593
|
_proxyFormState.isValid && isValid !== _formState.isValid ?
|
|
36516
36594
|
{} :
|
|
36517
36595
|
{ name }),
|
|
36518
|
-
...(_options.resolver ? { isValid } : {}),
|
|
36519
|
-
errors: _formState.errors
|
|
36520
|
-
isValidating: false });
|
|
36596
|
+
...(_options.resolver || !name ? { isValid } : {}),
|
|
36597
|
+
errors: _formState.errors });
|
|
36521
36598
|
|
|
36522
36599
|
options.shouldFocus &&
|
|
36523
36600
|
!validationResult &&
|
|
36524
|
-
|
|
36601
|
+
iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
|
|
36525
36602
|
return validationResult;
|
|
36526
36603
|
};
|
|
36527
36604
|
const getValues = (fieldNames) => {
|
|
36528
36605
|
const values = {
|
|
36529
|
-
..._defaultValues
|
|
36530
|
-
...(_stateFlags.mount ? _formValues : {}) };
|
|
36606
|
+
...(_state.mount ? _formValues : _defaultValues) };
|
|
36531
36607
|
|
|
36532
36608
|
return isUndefined(fieldNames) ?
|
|
36533
36609
|
values :
|
|
@@ -36538,20 +36614,24 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36538
36614
|
const getFieldState = (name, formState) => ({
|
|
36539
36615
|
invalid: !!get((formState || _formState).errors, name),
|
|
36540
36616
|
isDirty: !!get((formState || _formState).dirtyFields, name),
|
|
36541
|
-
|
|
36542
|
-
|
|
36617
|
+
error: get((formState || _formState).errors, name),
|
|
36618
|
+
isValidating: !!get(_formState.validatingFields, name),
|
|
36619
|
+
isTouched: !!get((formState || _formState).touchedFields, name) });
|
|
36543
36620
|
|
|
36544
36621
|
const clearErrors = (name) => {
|
|
36545
|
-
name
|
|
36546
|
-
convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName))
|
|
36547
|
-
_formState.errors = {};
|
|
36622
|
+
name &&
|
|
36623
|
+
convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
|
|
36548
36624
|
_subjects.state.next({
|
|
36549
|
-
errors: _formState.errors });
|
|
36625
|
+
errors: name ? _formState.errors : {} });
|
|
36550
36626
|
|
|
36551
36627
|
};
|
|
36552
36628
|
const setError = (name, error, options) => {
|
|
36553
36629
|
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
|
36630
|
+
const currentError = get(_formState.errors, name) || {};
|
|
36631
|
+
// Don't override existing error messages elsewhere in the object tree.
|
|
36632
|
+
const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
|
|
36554
36633
|
set(_formState.errors, name, {
|
|
36634
|
+
...restOfErrorTree,
|
|
36555
36635
|
...error,
|
|
36556
36636
|
ref });
|
|
36557
36637
|
|
|
@@ -36563,38 +36643,52 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36563
36643
|
options && options.shouldFocus && ref && ref.focus && ref.focus();
|
|
36564
36644
|
};
|
|
36565
36645
|
const watch = (name, defaultValue) => isFunction(name) ?
|
|
36566
|
-
_subjects.
|
|
36567
|
-
next: (
|
|
36646
|
+
_subjects.values.subscribe({
|
|
36647
|
+
next: (payload) => name(_getWatch(undefined, defaultValue), payload) }) :
|
|
36568
36648
|
|
|
36569
36649
|
_getWatch(name, defaultValue, true);
|
|
36570
36650
|
const unregister = (name, options = {}) => {
|
|
36571
36651
|
for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
|
|
36572
36652
|
_names.mount.delete(fieldName);
|
|
36573
36653
|
_names.array.delete(fieldName);
|
|
36574
|
-
if (
|
|
36575
|
-
|
|
36576
|
-
|
|
36577
|
-
|
|
36578
|
-
|
|
36579
|
-
|
|
36580
|
-
|
|
36581
|
-
|
|
36582
|
-
|
|
36583
|
-
|
|
36584
|
-
|
|
36585
|
-
|
|
36586
|
-
}
|
|
36587
|
-
_subjects.
|
|
36654
|
+
if (!options.keepValue) {
|
|
36655
|
+
unset(_fields, fieldName);
|
|
36656
|
+
unset(_formValues, fieldName);
|
|
36657
|
+
}
|
|
36658
|
+
!options.keepError && unset(_formState.errors, fieldName);
|
|
36659
|
+
!options.keepDirty && unset(_formState.dirtyFields, fieldName);
|
|
36660
|
+
!options.keepTouched && unset(_formState.touchedFields, fieldName);
|
|
36661
|
+
!options.keepIsValidating &&
|
|
36662
|
+
unset(_formState.validatingFields, fieldName);
|
|
36663
|
+
!_options.shouldUnregister &&
|
|
36664
|
+
!options.keepDefaultValue &&
|
|
36665
|
+
unset(_defaultValues, fieldName);
|
|
36666
|
+
}
|
|
36667
|
+
_subjects.values.next({
|
|
36668
|
+
values: { ..._formValues } });
|
|
36669
|
+
|
|
36588
36670
|
_subjects.state.next({
|
|
36589
36671
|
..._formState,
|
|
36590
36672
|
...(!options.keepDirty ? {} : { isDirty: _getDirty() }) });
|
|
36591
36673
|
|
|
36592
36674
|
!options.keepIsValid && _updateValid();
|
|
36593
36675
|
};
|
|
36676
|
+
const _updateDisabledField = ({ disabled, name, field, fields, value }) => {
|
|
36677
|
+
if (isBoolean(disabled) && _state.mount || !!disabled) {
|
|
36678
|
+
const inputValue = disabled ?
|
|
36679
|
+
undefined :
|
|
36680
|
+
isUndefined(value) ?
|
|
36681
|
+
getFieldValue(field ? field._f : get(fields, name)._f) :
|
|
36682
|
+
value;
|
|
36683
|
+
set(_formValues, name, inputValue);
|
|
36684
|
+
updateTouchAndDirty(name, inputValue, false, false, true);
|
|
36685
|
+
}
|
|
36686
|
+
};
|
|
36594
36687
|
const register = (name, options = {}) => {
|
|
36595
36688
|
let field = get(_fields, name);
|
|
36596
36689
|
const disabledIsDefined = isBoolean(options.disabled);
|
|
36597
36690
|
set(_fields, name, {
|
|
36691
|
+
...(field || {}),
|
|
36598
36692
|
_f: {
|
|
36599
36693
|
...(field && field._f ? field._f : { ref: { name } }),
|
|
36600
36694
|
name,
|
|
@@ -36603,15 +36697,20 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36603
36697
|
|
|
36604
36698
|
|
|
36605
36699
|
_names.mount.add(name);
|
|
36606
|
-
field
|
|
36607
|
-
|
|
36608
|
-
|
|
36609
|
-
|
|
36610
|
-
|
|
36611
|
-
|
|
36700
|
+
if (field) {
|
|
36701
|
+
_updateDisabledField({
|
|
36702
|
+
field,
|
|
36703
|
+
disabled: options.disabled,
|
|
36704
|
+
name,
|
|
36705
|
+
value: options.value });
|
|
36706
|
+
|
|
36707
|
+
} else
|
|
36708
|
+
{
|
|
36709
|
+
updateValidAndValue(name, true, options.value);
|
|
36710
|
+
}
|
|
36612
36711
|
return {
|
|
36613
36712
|
...(disabledIsDefined ? { disabled: options.disabled } : {}),
|
|
36614
|
-
...(_options.
|
|
36713
|
+
...(_options.progressive ?
|
|
36615
36714
|
{
|
|
36616
36715
|
required: !!options.required,
|
|
36617
36716
|
min: getRuleValue(options.min),
|
|
@@ -36648,9 +36747,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36648
36747
|
refs: [
|
|
36649
36748
|
...refs.filter(live),
|
|
36650
36749
|
fieldRef,
|
|
36651
|
-
...(
|
|
36652
|
-
[{}] :
|
|
36653
|
-
[])],
|
|
36750
|
+
...(Array.isArray(get(_defaultValues, name)) ? [{}] : [])],
|
|
36654
36751
|
|
|
36655
36752
|
ref: { type: fieldRef.type, name } } :
|
|
36656
36753
|
|
|
@@ -36665,69 +36762,86 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36665
36762
|
field._f.mount = false;
|
|
36666
36763
|
}
|
|
36667
36764
|
(_options.shouldUnregister || options.shouldUnregister) &&
|
|
36668
|
-
!(isNameInFieldArray(_names.array, name) &&
|
|
36765
|
+
!(isNameInFieldArray(_names.array, name) && _state.action) &&
|
|
36669
36766
|
_names.unMount.add(name);
|
|
36670
36767
|
}
|
|
36671
36768
|
} };
|
|
36672
36769
|
|
|
36673
36770
|
};
|
|
36771
|
+
const _focusError = () => _options.shouldFocusError &&
|
|
36772
|
+
iterateFieldsByAction(_fields, _focusInput, _names.mount);
|
|
36773
|
+
const _disableForm = (disabled) => {
|
|
36774
|
+
if (isBoolean(disabled)) {
|
|
36775
|
+
_subjects.state.next({ disabled });
|
|
36776
|
+
iterateFieldsByAction(_fields, (ref, name) => {
|
|
36777
|
+
const currentField = get(_fields, name);
|
|
36778
|
+
if (currentField) {
|
|
36779
|
+
ref.disabled = currentField._f.disabled || disabled;
|
|
36780
|
+
if (Array.isArray(currentField._f.refs)) {
|
|
36781
|
+
currentField._f.refs.forEach((inputRef) => {
|
|
36782
|
+
inputRef.disabled = currentField._f.disabled || disabled;
|
|
36783
|
+
});
|
|
36784
|
+
}
|
|
36785
|
+
}
|
|
36786
|
+
}, 0, false);
|
|
36787
|
+
}
|
|
36788
|
+
};
|
|
36674
36789
|
const handleSubmit = (onValid, onInvalid) => async (e) => {
|
|
36790
|
+
let onValidError = undefined;
|
|
36675
36791
|
if (e) {
|
|
36676
36792
|
e.preventDefault && e.preventDefault();
|
|
36677
36793
|
e.persist && e.persist();
|
|
36678
36794
|
}
|
|
36679
|
-
let hasNoPromiseError = true;
|
|
36680
36795
|
let fieldValues = cloneObject(_formValues);
|
|
36681
36796
|
_subjects.state.next({
|
|
36682
36797
|
isSubmitting: true });
|
|
36683
36798
|
|
|
36684
|
-
|
|
36685
|
-
|
|
36686
|
-
|
|
36687
|
-
|
|
36688
|
-
|
|
36689
|
-
|
|
36690
|
-
|
|
36691
|
-
|
|
36692
|
-
|
|
36693
|
-
|
|
36694
|
-
|
|
36695
|
-
|
|
36696
|
-
isSubmitting: true });
|
|
36799
|
+
if (_options.resolver) {
|
|
36800
|
+
const { errors, values } = await _executeSchema();
|
|
36801
|
+
_formState.errors = errors;
|
|
36802
|
+
fieldValues = values;
|
|
36803
|
+
} else
|
|
36804
|
+
{
|
|
36805
|
+
await executeBuiltInValidation(_fields);
|
|
36806
|
+
}
|
|
36807
|
+
unset(_formState.errors, 'root');
|
|
36808
|
+
if (isEmptyObject(_formState.errors)) {
|
|
36809
|
+
_subjects.state.next({
|
|
36810
|
+
errors: {} });
|
|
36697
36811
|
|
|
36812
|
+
try {
|
|
36698
36813
|
await onValid(fieldValues, e);
|
|
36699
|
-
} else
|
|
36700
|
-
{
|
|
36701
|
-
if (onInvalid) {
|
|
36702
|
-
await onInvalid({ ..._formState.errors }, e);
|
|
36703
|
-
}
|
|
36704
|
-
_options.shouldFocusError &&
|
|
36705
|
-
focusFieldBy(_fields, (key) => get(_formState.errors, key), _names.mount);
|
|
36706
36814
|
}
|
|
36707
|
-
|
|
36708
|
-
|
|
36709
|
-
|
|
36710
|
-
|
|
36711
|
-
} finally
|
|
36815
|
+
catch (error) {
|
|
36816
|
+
onValidError = error;
|
|
36817
|
+
}
|
|
36818
|
+
} else
|
|
36712
36819
|
{
|
|
36713
|
-
|
|
36714
|
-
|
|
36715
|
-
|
|
36716
|
-
|
|
36717
|
-
|
|
36718
|
-
|
|
36719
|
-
|
|
36820
|
+
if (onInvalid) {
|
|
36821
|
+
await onInvalid({ ..._formState.errors }, e);
|
|
36822
|
+
}
|
|
36823
|
+
_focusError();
|
|
36824
|
+
setTimeout(_focusError);
|
|
36825
|
+
}
|
|
36826
|
+
_subjects.state.next({
|
|
36827
|
+
isSubmitted: true,
|
|
36828
|
+
isSubmitting: false,
|
|
36829
|
+
isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
|
|
36830
|
+
submitCount: _formState.submitCount + 1,
|
|
36831
|
+
errors: _formState.errors });
|
|
36720
36832
|
|
|
36833
|
+
if (onValidError) {
|
|
36834
|
+
throw onValidError;
|
|
36721
36835
|
}
|
|
36722
36836
|
};
|
|
36723
36837
|
const resetField = (name, options = {}) => {
|
|
36724
36838
|
if (get(_fields, name)) {
|
|
36725
36839
|
if (isUndefined(options.defaultValue)) {
|
|
36726
|
-
setValue(name, get(_defaultValues, name));
|
|
36840
|
+
setValue(name, cloneObject(get(_defaultValues, name)));
|
|
36727
36841
|
} else
|
|
36728
36842
|
{
|
|
36729
36843
|
setValue(name, options.defaultValue);
|
|
36730
|
-
set(_defaultValues, name, options.defaultValue);
|
|
36844
|
+
set(_defaultValues, name, cloneObject(options.defaultValue));
|
|
36731
36845
|
}
|
|
36732
36846
|
if (!options.keepTouched) {
|
|
36733
36847
|
unset(_formState.touchedFields, name);
|
|
@@ -36735,7 +36849,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36735
36849
|
if (!options.keepDirty) {
|
|
36736
36850
|
unset(_formState.dirtyFields, name);
|
|
36737
36851
|
_formState.isDirty = options.defaultValue ?
|
|
36738
|
-
_getDirty(name, get(_defaultValues, name)) :
|
|
36852
|
+
_getDirty(name, cloneObject(get(_defaultValues, name))) :
|
|
36739
36853
|
_getDirty();
|
|
36740
36854
|
}
|
|
36741
36855
|
if (!options.keepError) {
|
|
@@ -36745,12 +36859,11 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36745
36859
|
_subjects.state.next({ ..._formState });
|
|
36746
36860
|
}
|
|
36747
36861
|
};
|
|
36748
|
-
const
|
|
36749
|
-
const updatedValues = formValues
|
|
36862
|
+
const _reset = (formValues, keepStateOptions = {}) => {
|
|
36863
|
+
const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
|
|
36750
36864
|
const cloneUpdatedValues = cloneObject(updatedValues);
|
|
36751
|
-
const
|
|
36752
|
-
|
|
36753
|
-
_defaultValues;
|
|
36865
|
+
const isEmptyResetValues = isEmptyObject(formValues);
|
|
36866
|
+
const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;
|
|
36754
36867
|
if (!keepStateOptions.keepDefaultValues) {
|
|
36755
36868
|
_defaultValues = updatedValues;
|
|
36756
36869
|
}
|
|
@@ -36770,13 +36883,13 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36770
36883
|
const fieldReference = Array.isArray(field._f.refs) ?
|
|
36771
36884
|
field._f.refs[0] :
|
|
36772
36885
|
field._f.ref;
|
|
36773
|
-
|
|
36774
|
-
|
|
36775
|
-
|
|
36886
|
+
if (isHTMLElement(fieldReference)) {
|
|
36887
|
+
const form = fieldReference.closest('form');
|
|
36888
|
+
if (form) {
|
|
36889
|
+
form.reset();
|
|
36776
36890
|
break;
|
|
36777
36891
|
}
|
|
36778
36892
|
}
|
|
36779
|
-
catch (_a) {}
|
|
36780
36893
|
}
|
|
36781
36894
|
}
|
|
36782
36895
|
}
|
|
@@ -36786,82 +36899,123 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36786
36899
|
keepStateOptions.keepDefaultValues ?
|
|
36787
36900
|
cloneObject(_defaultValues) :
|
|
36788
36901
|
{} :
|
|
36789
|
-
|
|
36902
|
+
cloneObject(values);
|
|
36790
36903
|
_subjects.array.next({
|
|
36791
|
-
values });
|
|
36904
|
+
values: { ...values } });
|
|
36792
36905
|
|
|
36793
|
-
_subjects.
|
|
36794
|
-
values });
|
|
36906
|
+
_subjects.values.next({
|
|
36907
|
+
values: { ...values } });
|
|
36795
36908
|
|
|
36796
36909
|
}
|
|
36797
36910
|
_names = {
|
|
36798
|
-
mount: new Set(),
|
|
36911
|
+
mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
|
|
36799
36912
|
unMount: new Set(),
|
|
36800
36913
|
array: new Set(),
|
|
36801
36914
|
watch: new Set(),
|
|
36802
36915
|
watchAll: false,
|
|
36803
36916
|
focus: '' };
|
|
36804
36917
|
|
|
36805
|
-
|
|
36806
|
-
!_proxyFormState.isValid ||
|
|
36807
|
-
|
|
36918
|
+
_state.mount =
|
|
36919
|
+
!_proxyFormState.isValid ||
|
|
36920
|
+
!!keepStateOptions.keepIsValid ||
|
|
36921
|
+
!!keepStateOptions.keepDirtyValues;
|
|
36922
|
+
_state.watch = !!props.shouldUnregister;
|
|
36808
36923
|
_subjects.state.next({
|
|
36809
36924
|
submitCount: keepStateOptions.keepSubmitCount ?
|
|
36810
36925
|
_formState.submitCount :
|
|
36811
36926
|
0,
|
|
36812
|
-
isDirty:
|
|
36927
|
+
isDirty: isEmptyResetValues ?
|
|
36928
|
+
false :
|
|
36929
|
+
keepStateOptions.keepDirty ?
|
|
36813
36930
|
_formState.isDirty :
|
|
36814
36931
|
!!(keepStateOptions.keepDefaultValues &&
|
|
36815
36932
|
!deepEqual(formValues, _defaultValues)),
|
|
36816
36933
|
isSubmitted: keepStateOptions.keepIsSubmitted ?
|
|
36817
36934
|
_formState.isSubmitted :
|
|
36818
36935
|
false,
|
|
36819
|
-
dirtyFields:
|
|
36936
|
+
dirtyFields: isEmptyResetValues ?
|
|
36937
|
+
{} :
|
|
36938
|
+
keepStateOptions.keepDirtyValues ?
|
|
36939
|
+
keepStateOptions.keepDefaultValues && _formValues ?
|
|
36940
|
+
getDirtyFields(_defaultValues, _formValues) :
|
|
36820
36941
|
_formState.dirtyFields :
|
|
36821
36942
|
keepStateOptions.keepDefaultValues && formValues ?
|
|
36822
36943
|
getDirtyFields(_defaultValues, formValues) :
|
|
36944
|
+
keepStateOptions.keepDirty ?
|
|
36945
|
+
_formState.dirtyFields :
|
|
36823
36946
|
{},
|
|
36824
36947
|
touchedFields: keepStateOptions.keepTouched ?
|
|
36825
36948
|
_formState.touchedFields :
|
|
36826
36949
|
{},
|
|
36827
|
-
errors: keepStateOptions.keepErrors ?
|
|
36828
|
-
|
|
36829
|
-
|
|
36830
|
-
|
|
36831
|
-
|
|
36950
|
+
errors: keepStateOptions.keepErrors ? _formState.errors : {},
|
|
36951
|
+
isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful ?
|
|
36952
|
+
_formState.isSubmitSuccessful :
|
|
36953
|
+
false,
|
|
36954
|
+
isSubmitting: false });
|
|
36832
36955
|
|
|
36833
36956
|
};
|
|
36957
|
+
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues) ?
|
|
36958
|
+
formValues(_formValues) :
|
|
36959
|
+
formValues, keepStateOptions);
|
|
36834
36960
|
const setFocus = (name, options = {}) => {
|
|
36835
|
-
const field = get(_fields, name)
|
|
36836
|
-
const
|
|
36837
|
-
|
|
36838
|
-
|
|
36961
|
+
const field = get(_fields, name);
|
|
36962
|
+
const fieldReference = field && field._f;
|
|
36963
|
+
if (fieldReference) {
|
|
36964
|
+
const fieldRef = fieldReference.refs ?
|
|
36965
|
+
fieldReference.refs[0] :
|
|
36966
|
+
fieldReference.ref;
|
|
36967
|
+
if (fieldRef.focus) {
|
|
36968
|
+
fieldRef.focus();
|
|
36969
|
+
options.shouldSelect && fieldRef.select();
|
|
36970
|
+
}
|
|
36971
|
+
}
|
|
36839
36972
|
};
|
|
36973
|
+
const _updateFormState = (updatedFormState) => {
|
|
36974
|
+
_formState = {
|
|
36975
|
+
..._formState,
|
|
36976
|
+
...updatedFormState };
|
|
36977
|
+
|
|
36978
|
+
};
|
|
36979
|
+
const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
|
|
36980
|
+
_options.defaultValues().then((values) => {
|
|
36981
|
+
reset(values, _options.resetOptions);
|
|
36982
|
+
_subjects.state.next({
|
|
36983
|
+
isLoading: false });
|
|
36984
|
+
|
|
36985
|
+
});
|
|
36840
36986
|
return {
|
|
36841
36987
|
control: {
|
|
36842
36988
|
register,
|
|
36843
36989
|
unregister,
|
|
36844
36990
|
getFieldState,
|
|
36991
|
+
handleSubmit,
|
|
36992
|
+
setError,
|
|
36845
36993
|
_executeSchema,
|
|
36846
36994
|
_getWatch,
|
|
36847
36995
|
_getDirty,
|
|
36848
36996
|
_updateValid,
|
|
36849
36997
|
_removeUnmounted,
|
|
36850
36998
|
_updateFieldArray,
|
|
36999
|
+
_updateDisabledField,
|
|
36851
37000
|
_getFieldArray,
|
|
37001
|
+
_reset,
|
|
37002
|
+
_resetDefaultValues,
|
|
37003
|
+
_updateFormState,
|
|
37004
|
+
_disableForm,
|
|
36852
37005
|
_subjects,
|
|
36853
37006
|
_proxyFormState,
|
|
37007
|
+
_setErrors,
|
|
36854
37008
|
get _fields() {
|
|
36855
37009
|
return _fields;
|
|
36856
37010
|
},
|
|
36857
37011
|
get _formValues() {
|
|
36858
37012
|
return _formValues;
|
|
36859
37013
|
},
|
|
36860
|
-
get
|
|
36861
|
-
return
|
|
37014
|
+
get _state() {
|
|
37015
|
+
return _state;
|
|
36862
37016
|
},
|
|
36863
|
-
set
|
|
36864
|
-
|
|
37017
|
+
set _state(value) {
|
|
37018
|
+
_state = value;
|
|
36865
37019
|
},
|
|
36866
37020
|
get _defaultValues() {
|
|
36867
37021
|
return _defaultValues;
|
|
@@ -36904,84 +37058,116 @@ Check the top-level render call using <` + t + ">.");
|
|
|
36904
37058
|
|
|
36905
37059
|
}
|
|
36906
37060
|
|
|
36907
|
-
/**
|
|
36908
|
-
* Custom hook to manage the entire form.
|
|
36909
|
-
*
|
|
36910
|
-
* @remarks
|
|
36911
|
-
* [API](https://react-hook-form.com/
|
|
36912
|
-
*
|
|
36913
|
-
* @param props - form configuration and validation parameters.
|
|
36914
|
-
*
|
|
36915
|
-
* @returns methods - individual functions to manage the form state. {@link UseFormReturn}
|
|
36916
|
-
*
|
|
36917
|
-
* @example
|
|
36918
|
-
* ```tsx
|
|
36919
|
-
* function App() {
|
|
36920
|
-
* const { register, handleSubmit, watch, formState: { errors } } = useForm();
|
|
36921
|
-
* const onSubmit = data => console.log(data);
|
|
36922
|
-
*
|
|
36923
|
-
* console.log(watch("example"));
|
|
36924
|
-
*
|
|
36925
|
-
* return (
|
|
36926
|
-
* <form onSubmit={handleSubmit(onSubmit)}>
|
|
36927
|
-
* <input defaultValue="test" {...register("example")} />
|
|
36928
|
-
* <input {...register("exampleRequired", { required: true })} />
|
|
36929
|
-
* {errors.exampleRequired && <span>This field is required</span>}
|
|
36930
|
-
* <
|
|
36931
|
-
* </form>
|
|
36932
|
-
* );
|
|
36933
|
-
* }
|
|
36934
|
-
* ```
|
|
37061
|
+
/**
|
|
37062
|
+
* Custom hook to manage the entire form.
|
|
37063
|
+
*
|
|
37064
|
+
* @remarks
|
|
37065
|
+
* [API](https://react-hook-form.com/docs/useform) • [Demo](https://codesandbox.io/s/react-hook-form-get-started-ts-5ksmm) • [Video](https://www.youtube.com/watch?v=RkXv4AXXC_4)
|
|
37066
|
+
*
|
|
37067
|
+
* @param props - form configuration and validation parameters.
|
|
37068
|
+
*
|
|
37069
|
+
* @returns methods - individual functions to manage the form state. {@link UseFormReturn}
|
|
37070
|
+
*
|
|
37071
|
+
* @example
|
|
37072
|
+
* ```tsx
|
|
37073
|
+
* function App() {
|
|
37074
|
+
* const { register, handleSubmit, watch, formState: { errors } } = useForm();
|
|
37075
|
+
* const onSubmit = data => console.log(data);
|
|
37076
|
+
*
|
|
37077
|
+
* console.log(watch("example"));
|
|
37078
|
+
*
|
|
37079
|
+
* return (
|
|
37080
|
+
* <form onSubmit={handleSubmit(onSubmit)}>
|
|
37081
|
+
* <input defaultValue="test" {...register("example")} />
|
|
37082
|
+
* <input {...register("exampleRequired", { required: true })} />
|
|
37083
|
+
* {errors.exampleRequired && <span>This field is required</span>}
|
|
37084
|
+
* <button>Submit</button>
|
|
37085
|
+
* </form>
|
|
37086
|
+
* );
|
|
37087
|
+
* }
|
|
37088
|
+
* ```
|
|
36935
37089
|
*/
|
|
36936
37090
|
function useForm(props = {}) {
|
|
36937
37091
|
const _formControl = React__default["default"].useRef();
|
|
37092
|
+
const _values = React__default["default"].useRef();
|
|
36938
37093
|
const [formState, updateFormState] = React__default["default"].useState({
|
|
36939
37094
|
isDirty: false,
|
|
36940
37095
|
isValidating: false,
|
|
36941
|
-
|
|
37096
|
+
isLoading: isFunction(props.defaultValues),
|
|
36942
37097
|
isSubmitted: false,
|
|
36943
|
-
submitCount: 0,
|
|
36944
|
-
touchedFields: {},
|
|
36945
37098
|
isSubmitting: false,
|
|
36946
37099
|
isSubmitSuccessful: false,
|
|
36947
37100
|
isValid: false,
|
|
36948
|
-
|
|
37101
|
+
submitCount: 0,
|
|
37102
|
+
dirtyFields: {},
|
|
37103
|
+
touchedFields: {},
|
|
37104
|
+
validatingFields: {},
|
|
37105
|
+
errors: props.errors || {},
|
|
37106
|
+
disabled: props.disabled || false,
|
|
37107
|
+
defaultValues: isFunction(props.defaultValues) ?
|
|
37108
|
+
undefined :
|
|
37109
|
+
props.defaultValues });
|
|
36949
37110
|
|
|
36950
|
-
if (_formControl.current) {
|
|
36951
|
-
_formControl.current.control._options = props;
|
|
36952
|
-
} else
|
|
36953
|
-
{
|
|
37111
|
+
if (!_formControl.current) {
|
|
36954
37112
|
_formControl.current = {
|
|
36955
37113
|
...createFormControl(props),
|
|
36956
37114
|
formState };
|
|
36957
37115
|
|
|
36958
37116
|
}
|
|
36959
37117
|
const control = _formControl.current.control;
|
|
36960
|
-
|
|
36961
|
-
if (shouldRenderFormState(value, control._proxyFormState, true)) {
|
|
36962
|
-
control._formState = {
|
|
36963
|
-
...control._formState,
|
|
36964
|
-
...value };
|
|
36965
|
-
|
|
36966
|
-
updateFormState({ ...control._formState });
|
|
36967
|
-
}
|
|
36968
|
-
}, [control]);
|
|
37118
|
+
control._options = props;
|
|
36969
37119
|
useSubscribe({
|
|
36970
37120
|
subject: control._subjects.state,
|
|
36971
|
-
|
|
37121
|
+
next: (value) => {
|
|
37122
|
+
if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
|
|
37123
|
+
updateFormState({ ...control._formState });
|
|
37124
|
+
}
|
|
37125
|
+
} });
|
|
36972
37126
|
|
|
37127
|
+
React__default["default"].useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
|
|
36973
37128
|
React__default["default"].useEffect(() => {
|
|
36974
|
-
if (
|
|
36975
|
-
|
|
36976
|
-
|
|
37129
|
+
if (control._proxyFormState.isDirty) {
|
|
37130
|
+
const isDirty = control._getDirty();
|
|
37131
|
+
if (isDirty !== formState.isDirty) {
|
|
37132
|
+
control._subjects.state.next({
|
|
37133
|
+
isDirty });
|
|
37134
|
+
|
|
37135
|
+
}
|
|
36977
37136
|
}
|
|
36978
|
-
|
|
36979
|
-
|
|
36980
|
-
|
|
37137
|
+
}, [control, formState.isDirty]);
|
|
37138
|
+
React__default["default"].useEffect(() => {
|
|
37139
|
+
if (props.values && !deepEqual(props.values, _values.current)) {
|
|
37140
|
+
control._reset(props.values, control._options.resetOptions);
|
|
37141
|
+
_values.current = props.values;
|
|
37142
|
+
updateFormState((state) => ({ ...state }));
|
|
37143
|
+
} else
|
|
37144
|
+
{
|
|
37145
|
+
control._resetDefaultValues();
|
|
37146
|
+
}
|
|
37147
|
+
}, [props.values, control]);
|
|
37148
|
+
React__default["default"].useEffect(() => {
|
|
37149
|
+
if (props.errors) {
|
|
37150
|
+
control._setErrors(props.errors);
|
|
37151
|
+
}
|
|
37152
|
+
}, [props.errors, control]);
|
|
37153
|
+
React__default["default"].useEffect(() => {
|
|
37154
|
+
if (!control._state.mount) {
|
|
37155
|
+
control._updateValid();
|
|
37156
|
+
control._state.mount = true;
|
|
37157
|
+
}
|
|
37158
|
+
if (control._state.watch) {
|
|
37159
|
+
control._state.watch = false;
|
|
37160
|
+
control._subjects.state.next({ ...control._formState });
|
|
36981
37161
|
}
|
|
36982
37162
|
control._removeUnmounted();
|
|
36983
37163
|
});
|
|
36984
|
-
|
|
37164
|
+
React__default["default"].useEffect(() => {
|
|
37165
|
+
props.shouldUnregister &&
|
|
37166
|
+
control._subjects.values.next({
|
|
37167
|
+
values: control._getWatch() });
|
|
37168
|
+
|
|
37169
|
+
}, [props.shouldUnregister, control]);
|
|
37170
|
+
_formControl.current.formState = getProxyFormState(formState, control);
|
|
36985
37171
|
return _formControl.current;
|
|
36986
37172
|
}
|
|
36987
37173
|
|
|
@@ -37286,11 +37472,17 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37286
37472
|
return undefined;
|
|
37287
37473
|
};
|
|
37288
37474
|
|
|
37475
|
+
var isValidEmail = function (email) {
|
|
37476
|
+
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
37477
|
+
return emailRegex.test(email);
|
|
37478
|
+
};
|
|
37479
|
+
|
|
37289
37480
|
var AUTO_PROGRESS_DELAY = 850;
|
|
37290
37481
|
var QuestionData = function (_a) {
|
|
37291
37482
|
var _b, _c, _d, _e, _f;
|
|
37292
37483
|
var question = _a.question,control = _a.control,getValues = _a.getValues,labels = _a.labels,_g = _a.inputAutoFocus,inputAutoFocus = _g === void 0 ? false : _g,_h = _a.submitAndMoveToNextQuestion,submitAndMoveToNextQuestion = _h === void 0 ? lodash.exports.noop : _h,_j = _a.onAnswerChange,onAnswerChange = _j === void 0 ? lodash.exports.noop : _j,_k = _a.shouldAutoProgress,shouldAutoProgress = _k === void 0 ? function () {return false;} : _k;
|
|
37293
37484
|
var config = question === null || question === void 0 ? void 0 : question.questionConfig;
|
|
37485
|
+
useValidate().validateDateResponse;
|
|
37294
37486
|
switch (question.userQuestionType) {
|
|
37295
37487
|
case exports.UserQuestionType.YesNo:
|
|
37296
37488
|
return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: "", rules: { required: config === null || config === void 0 ? void 0 : config.mandatory }, render: function (_a) {
|
|
@@ -37421,6 +37613,19 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37421
37613
|
onAnswerChange();
|
|
37422
37614
|
}, touchTooltipLabel: (_b = labels.slider) === null || _b === void 0 ? void 0 : _b.tooltip_guide, id: question.id, sliderConfig: config === null || config === void 0 ? void 0 : config.slider, value: value === '' ? undefined : value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
|
|
37423
37615
|
} });
|
|
37616
|
+
case exports.UserQuestionType.Email:
|
|
37617
|
+
return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, defaultValue: "", rules: {
|
|
37618
|
+
required: config === null || config === void 0 ? void 0 : config.mandatory,
|
|
37619
|
+
validate: function (value) {
|
|
37620
|
+
return isValidEmail(value);
|
|
37621
|
+
} },
|
|
37622
|
+
render: function (_a) {
|
|
37623
|
+
var _b = _a.field,onChange = _b.onChange,value = _b.value;
|
|
37624
|
+
return jsxRuntime.exports.jsx(InputField, { autoFocus: inputAutoFocus, type: "email", onChange: function (e) {
|
|
37625
|
+
onChange(e.target.value);
|
|
37626
|
+
onAnswerChange();
|
|
37627
|
+
}, label: question.title, id: question.id, value: value, mandatory: config === null || config === void 0 ? void 0 : config.mandatory });
|
|
37628
|
+
} });
|
|
37424
37629
|
case exports.UserQuestionType.Date:
|
|
37425
37630
|
return jsxRuntime.exports.jsx(Controller, { name: question.id, control: control, rules: {
|
|
37426
37631
|
required: config === null || config === void 0 ? void 0 : config.mandatory },
|
|
@@ -37725,25 +37930,32 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37725
37930
|
return [];
|
|
37726
37931
|
};
|
|
37727
37932
|
var getDirtyFieldValues = function (formMethods) {
|
|
37728
|
-
var
|
|
37933
|
+
var getValues = formMethods.getValues,getFieldState = formMethods.getFieldState;
|
|
37729
37934
|
var allValues = getValues();
|
|
37730
|
-
var dirtyValues = Object.keys(
|
|
37731
|
-
if (
|
|
37935
|
+
var dirtyValues = Object.keys(getValues()).reduce(function (acc, key) {
|
|
37936
|
+
if (getFieldState(key).isDirty) {
|
|
37732
37937
|
acc[key] = allValues[key];
|
|
37733
37938
|
}
|
|
37734
37939
|
return acc;
|
|
37735
37940
|
}, {});
|
|
37736
37941
|
return dirtyValues;
|
|
37737
37942
|
};
|
|
37943
|
+
var markInitialValuesAsDirty = function (_a) {
|
|
37944
|
+
var formMethods = _a.formMethods,defaultValues = _a.defaultValues,initialValues = _a.initialValues;
|
|
37945
|
+
formMethods.reset(defaultValues);
|
|
37946
|
+
Object.keys(initialValues).forEach(function (key) {
|
|
37947
|
+
formMethods.setValue(key, initialValues[key], {
|
|
37948
|
+
shouldDirty: true,
|
|
37949
|
+
shouldTouch: true });
|
|
37950
|
+
|
|
37951
|
+
});
|
|
37952
|
+
};
|
|
37738
37953
|
|
|
37739
37954
|
var useTraditionalForm = function (_a) {
|
|
37740
37955
|
var questions = _a.questions,evaluateDisplayConditions = _a.evaluateDisplayConditions,onSubmit = _a.onSubmit,errorLabels = _a.errorLabels,storedAnswers = _a.storedAnswers,_b = _a.autosaveAnswers,autosaveAnswers = _b === void 0 ? true : _b,onAnswersChange = _a.onAnswersChange;
|
|
37741
37956
|
var initialValues = convertToFormFormat(storedAnswers, questions);
|
|
37742
|
-
var defaultValues = !isEmpty(initialValues) && autosaveAnswers ?
|
|
37743
|
-
initialValues :
|
|
37744
|
-
getInitialValues(questions);
|
|
37745
37957
|
var formMethods = useForm({
|
|
37746
|
-
defaultValues:
|
|
37958
|
+
defaultValues: getInitialValues(questions),
|
|
37747
37959
|
shouldUnregister: false,
|
|
37748
37960
|
shouldFocusError: true,
|
|
37749
37961
|
mode: 'all' });
|
|
@@ -37780,6 +37992,23 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37780
37992
|
React.useEffect(function () {
|
|
37781
37993
|
updateQuestionVisibility();
|
|
37782
37994
|
}, [updateQuestionVisibility]);
|
|
37995
|
+
React.useEffect(function () {
|
|
37996
|
+
if (autosaveAnswers && !isEmpty(initialValues)) {
|
|
37997
|
+
markInitialValuesAsDirty({
|
|
37998
|
+
formMethods: formMethods,
|
|
37999
|
+
initialValues: initialValues,
|
|
38000
|
+
defaultValues: getInitialValues(questions) });
|
|
38001
|
+
|
|
38002
|
+
formMethods.trigger().then(function () {
|
|
38003
|
+
var _a;
|
|
38004
|
+
var allValues = formMethods.getValues();
|
|
38005
|
+
if (onAnswersChange) {
|
|
38006
|
+
onAnswersChange((_a = JSON.stringify(allValues)) !== null && _a !== void 0 ? _a : '{}');
|
|
38007
|
+
}
|
|
38008
|
+
updateQuestionVisibility();
|
|
38009
|
+
});
|
|
38010
|
+
}
|
|
38011
|
+
}, []);
|
|
37783
38012
|
var handleConvertAndSubmitForm = function (formResponse) {return __awaiter(void 0, void 0, void 0, function () {
|
|
37784
38013
|
return __generator(this, function (_a) {
|
|
37785
38014
|
switch (_a.label) {
|
|
@@ -37797,17 +38026,17 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37797
38026
|
});
|
|
37798
38027
|
});};
|
|
37799
38028
|
var submitForm = function () {return __awaiter(void 0, void 0, void 0, function () {
|
|
37800
|
-
var
|
|
38029
|
+
var formErrors;
|
|
37801
38030
|
return __generator(this, function (_a) {
|
|
37802
38031
|
switch (_a.label) {
|
|
37803
38032
|
case 0:return [4, updateQuestionVisibility()];
|
|
37804
38033
|
case 1:
|
|
37805
38034
|
_a.sent();
|
|
37806
|
-
|
|
38035
|
+
formErrors = visibleQuestions.flatMap(function (vq) {
|
|
37807
38036
|
return getErrorsForQuestion(vq, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse);
|
|
37808
38037
|
});
|
|
37809
|
-
setErrors(
|
|
37810
|
-
if (
|
|
38038
|
+
setErrors(formErrors);
|
|
38039
|
+
if (formErrors.length === 0) {
|
|
37811
38040
|
setFormHasErrors(false);
|
|
37812
38041
|
formMethods.handleSubmit(handleConvertAndSubmitForm)();
|
|
37813
38042
|
} else
|
|
@@ -37833,11 +38062,8 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37833
38062
|
var questions = _a.questions,evaluateDisplayConditions = _a.evaluateDisplayConditions,onSubmit = _a.onSubmit,errorLabels = _a.errorLabels,storedAnswers = _a.storedAnswers,_b = _a.autosaveAnswers,autosaveAnswers = _b === void 0 ? true : _b,onAnswersChange = _a.onAnswersChange;
|
|
37834
38063
|
var initialValues = convertToFormFormat(storedAnswers, questions);
|
|
37835
38064
|
var _c = useValidate(),isValidE164Number = _c.isValidE164Number,validateDateResponse = _c.validateDateResponse,validateNumberResponse = _c.validateNumberResponse;
|
|
37836
|
-
var defaultValues = !isEmpty(initialValues) && autosaveAnswers ?
|
|
37837
|
-
initialValues :
|
|
37838
|
-
getInitialValues(questions);
|
|
37839
38065
|
var formMethods = useForm({
|
|
37840
|
-
defaultValues:
|
|
38066
|
+
defaultValues: getInitialValues(questions),
|
|
37841
38067
|
shouldUnregister: false,
|
|
37842
38068
|
shouldFocusError: true,
|
|
37843
38069
|
mode: 'all' });
|
|
@@ -37885,6 +38111,23 @@ Check the top-level render call using <` + t + ">.");
|
|
|
37885
38111
|
React.useEffect(function () {
|
|
37886
38112
|
updateQuestionVisibility();
|
|
37887
38113
|
}, [updateQuestionVisibility]);
|
|
38114
|
+
React.useEffect(function () {
|
|
38115
|
+
if (autosaveAnswers && !isEmpty(initialValues)) {
|
|
38116
|
+
markInitialValuesAsDirty({
|
|
38117
|
+
formMethods: formMethods,
|
|
38118
|
+
initialValues: initialValues,
|
|
38119
|
+
defaultValues: getInitialValues(questions) });
|
|
38120
|
+
|
|
38121
|
+
formMethods.trigger().then(function () {
|
|
38122
|
+
var _a;
|
|
38123
|
+
var allValues = formMethods.getValues();
|
|
38124
|
+
if (onAnswersChange) {
|
|
38125
|
+
onAnswersChange((_a = JSON.stringify(allValues)) !== null && _a !== void 0 ? _a : '{}');
|
|
38126
|
+
}
|
|
38127
|
+
updateQuestionVisibility();
|
|
38128
|
+
});
|
|
38129
|
+
}
|
|
38130
|
+
}, []);
|
|
37888
38131
|
var handleCheckForErrors = function (currentQuestion) {
|
|
37889
38132
|
var errorsWithoutCurrent = errors.filter(function (err) {return err.id !== (currentQuestion === null || currentQuestion === void 0 ? void 0 : currentQuestion.id);});
|
|
37890
38133
|
var existingErrors = getErrorsForQuestion(currentQuestion, formMethods, errorLabels, isValidE164Number, validateDateResponse, validateNumberResponse);
|
|
@@ -51896,6 +52139,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
51896
52139
|
exports.useScrollHint = useScrollHint;
|
|
51897
52140
|
exports.useTheme = useTheme;
|
|
51898
52141
|
exports.useTraditionalForm = useTraditionalForm;
|
|
52142
|
+
exports.useValidate = useValidate;
|
|
51899
52143
|
|
|
51900
52144
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
51901
52145
|
|