@onehat/ui 0.4.76 → 0.4.77
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/package.json +1 -1
- package/src/Components/Form/Form.js +35 -1
package/package.json
CHANGED
|
@@ -185,7 +185,27 @@ function Form(props) {
|
|
|
185
185
|
}),
|
|
186
186
|
initialValues = _.merge(startingValues, (record && !record.isDestroyed ? record.submitValues : {})),
|
|
187
187
|
defaultValues = isMultiple ? getNullFieldValues(initialValues, Repository) : initialValues, // when multiple entities, set all default values to null
|
|
188
|
-
validatorToUse =
|
|
188
|
+
validatorToUse = (() => {
|
|
189
|
+
// If a custom validator is provided, use it
|
|
190
|
+
if (validator) {
|
|
191
|
+
return validator;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// If we have a Repository with a schema, use it (with modifications for multiple records)
|
|
195
|
+
if (Repository?.schema?.model?.validator) {
|
|
196
|
+
return isMultiple
|
|
197
|
+
? disableRequiredYupFields(Repository.schema.model.validator)
|
|
198
|
+
: Repository.schema.model.validator;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// For forms with no fields (like reports), create a schema that defaults to valid
|
|
202
|
+
if (!items || items.length === 0) {
|
|
203
|
+
return yup.object().default({}); // This will make the form valid by default
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Fallback to empty schema that allows any fields and defaults to valid
|
|
207
|
+
return yup.object().noUnknown(false).default({});
|
|
208
|
+
})(),
|
|
189
209
|
{
|
|
190
210
|
control,
|
|
191
211
|
formState,
|
|
@@ -1131,6 +1151,20 @@ function Form(props) {
|
|
|
1131
1151
|
}, [formState.isDirty]);
|
|
1132
1152
|
}
|
|
1133
1153
|
|
|
1154
|
+
useEffect(() => {
|
|
1155
|
+
// For forms with no items (like some reports), manually trigger validation to set valid state
|
|
1156
|
+
if ((!items || items.length === 0) && !columnsConfig) {
|
|
1157
|
+
setTimeout(() => { // ensure the form is fully initialized
|
|
1158
|
+
trigger().then(() => {
|
|
1159
|
+
// Force validity to true for empty forms
|
|
1160
|
+
if (onValidityChange) {
|
|
1161
|
+
onValidityChange(true);
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
}, 0);
|
|
1165
|
+
}
|
|
1166
|
+
}, [items, columnsConfig, trigger, onValidityChange]);
|
|
1167
|
+
|
|
1134
1168
|
if (skipAll) {
|
|
1135
1169
|
return null;
|
|
1136
1170
|
}
|