@openg2p/registry-widgets 1.1.0-dev.8 → 1.1.0-dev.9
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/components/SectionRenderer.d.ts.map +1 -1
- package/dist/components/SectionsContainer.d.ts.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.esm.js +52 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +52 -18
- package/dist/index.js.map +1 -1
- package/dist/utils/sectionValidate.d.ts +9 -1
- package/dist/utils/sectionValidate.d.ts.map +1 -1
- package/dist/utils/validation.d.ts +6 -2
- package/dist/utils/validation.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SectionRenderer.d.ts","sourceRoot":"","sources":["../../src/components/SectionRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAyC,MAAM,UAAU,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAQ9D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AA2ClD,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,aAAa,CAAC;IACvB,wBAAwB,CAAC,EAAE,oBAAoB,CAAC,0BAA0B,CAAC,CAAC;IAC5E,UAAU,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAChD,aAAa,CAAC,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAC;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,CAA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-1523,9 +1523,13 @@ declare const getWidgetValue: (values: Record<string, any>, dataPath: string | R
|
|
|
1523
1523
|
declare const setWidgetValue: (currentValues: Record<string, any>, dataPath: string | Record<string, string> | undefined, widgetId: string, value: any) => Record<string, any>;
|
|
1524
1524
|
|
|
1525
1525
|
/**
|
|
1526
|
-
* Validate value against validation rules
|
|
1526
|
+
* Validate value against validation rules.
|
|
1527
|
+
*
|
|
1528
|
+
* @param skipRequired - When true, required-field checks are skipped (used by
|
|
1529
|
+
* per-section Save/Next buttons so the user can move between sections without
|
|
1530
|
+
* filling every mandatory field; only format/range checks still run).
|
|
1527
1531
|
*/
|
|
1528
|
-
declare const validateWidget: (value: any, validation: WidgetValidation | undefined, required?: boolean) => string[];
|
|
1532
|
+
declare const validateWidget: (value: any, validation: WidgetValidation | undefined, required?: boolean, skipRequired?: boolean) => string[];
|
|
1529
1533
|
/**
|
|
1530
1534
|
* Create Zod schema from validation config
|
|
1531
1535
|
*/
|
package/dist/index.esm.js
CHANGED
|
@@ -245,24 +245,27 @@ const getValidationPattern = (validationType) => {
|
|
|
245
245
|
};
|
|
246
246
|
|
|
247
247
|
/**
|
|
248
|
-
* Validate value against validation rules
|
|
248
|
+
* Validate value against validation rules.
|
|
249
|
+
*
|
|
250
|
+
* @param skipRequired - When true, required-field checks are skipped (used by
|
|
251
|
+
* per-section Save/Next buttons so the user can move between sections without
|
|
252
|
+
* filling every mandatory field; only format/range checks still run).
|
|
249
253
|
*/
|
|
250
|
-
const validateWidget = (value, validation, required = false) => {
|
|
254
|
+
const validateWidget = (value, validation, required = false, skipRequired = false) => {
|
|
251
255
|
const errors = [];
|
|
252
256
|
if (!validation && !required) {
|
|
253
257
|
return errors;
|
|
254
258
|
}
|
|
255
|
-
// Check required
|
|
256
|
-
const isRequired = validation?.required ?? required;
|
|
259
|
+
// Check required (skipped when navigating between sections)
|
|
260
|
+
const isRequired = !skipRequired && (validation?.required ?? required);
|
|
257
261
|
// For boolean, false is a valid value, so only check for null/undefined/empty string
|
|
258
262
|
const isEmpty = value === null || value === undefined || value === '';
|
|
259
263
|
if (isRequired && isEmpty) {
|
|
260
264
|
errors.push('This field is required');
|
|
261
265
|
return errors; // Return early if required field is empty
|
|
262
266
|
}
|
|
263
|
-
// Skip
|
|
264
|
-
|
|
265
|
-
if (isEmpty && !isRequired) {
|
|
267
|
+
// Skip format/range validations if value is empty
|
|
268
|
+
if (isEmpty) {
|
|
266
269
|
return errors;
|
|
267
270
|
}
|
|
268
271
|
if (!validation) {
|
|
@@ -3806,7 +3809,15 @@ const collectWidgets = (panels) => {
|
|
|
3806
3809
|
});
|
|
3807
3810
|
return widgets;
|
|
3808
3811
|
};
|
|
3809
|
-
|
|
3812
|
+
/**
|
|
3813
|
+
* Validate all widgets in a section and dispatch errors to the store.
|
|
3814
|
+
*
|
|
3815
|
+
* @param skipRequired - When true, required-field checks (widget-required,
|
|
3816
|
+
* validation.required, document-required) are skipped. Use this for
|
|
3817
|
+
* per-section Save/Next navigation so the user can advance without filling
|
|
3818
|
+
* every mandatory field; only format/range errors are reported.
|
|
3819
|
+
*/
|
|
3820
|
+
const sectionValidate = (section, currentSchemaData, dispatch, skipRequired = false) => {
|
|
3810
3821
|
const allWidgets = collectWidgets(section.panels);
|
|
3811
3822
|
let isValid = true;
|
|
3812
3823
|
for (const widget of allWidgets) {
|
|
@@ -3815,7 +3826,7 @@ const sectionValidate = (section, currentSchemaData, dispatch) => {
|
|
|
3815
3826
|
continue;
|
|
3816
3827
|
const widgetId = widget['widget-id'];
|
|
3817
3828
|
const value = getWidgetValue(currentSchemaData, widget['widget-data-path'], widgetId);
|
|
3818
|
-
const errors = validateWidget(value, widget['widget-data-validation'], widget['widget-required']);
|
|
3829
|
+
const errors = validateWidget(value, widget['widget-data-validation'], widget['widget-required'], skipRequired);
|
|
3819
3830
|
if (errors.length > 0) {
|
|
3820
3831
|
isValid = false;
|
|
3821
3832
|
dispatch(setTouched({ widgetId, touched: true }));
|
|
@@ -3826,10 +3837,10 @@ const sectionValidate = (section, currentSchemaData, dispatch) => {
|
|
|
3826
3837
|
dispatch(setError({ widgetId, errors: [] }));
|
|
3827
3838
|
}
|
|
3828
3839
|
}
|
|
3829
|
-
// Supporting Documents
|
|
3840
|
+
// Supporting Documents — only check required when not skipping required validation
|
|
3830
3841
|
section['section-supporting-documents']?.forEach((doc, index) => {
|
|
3831
3842
|
const widgetId = `supporting-doc-${section['section-id']}-${index}`;
|
|
3832
|
-
if (doc['document-required']) {
|
|
3843
|
+
if (!skipRequired && doc['document-required']) {
|
|
3833
3844
|
const file = getValueByPath(currentSchemaData, doc['document-data-path']);
|
|
3834
3845
|
if (!file) {
|
|
3835
3846
|
isValid = false;
|
|
@@ -4464,7 +4475,7 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
|
|
|
4464
4475
|
const sectionWidgets = collectWidgets(originalSection.panels);
|
|
4465
4476
|
const currentState = store.getState().widget;
|
|
4466
4477
|
const currentSchemaData = currentState.values || {};
|
|
4467
|
-
const isSectionValid = sectionValidate(originalSection, currentSchemaData, dispatch);
|
|
4478
|
+
const isSectionValid = sectionValidate(originalSection, currentSchemaData, dispatch, true);
|
|
4468
4479
|
if (!isSectionValid) {
|
|
4469
4480
|
return;
|
|
4470
4481
|
}
|
|
@@ -4530,7 +4541,7 @@ const SectionRenderer = ({ section, dataSourceRequestHandler: propDataSourceRequ
|
|
|
4530
4541
|
const sectionWidgets = collectWidgets(originalSection.panels);
|
|
4531
4542
|
const currentState = store.getState().widget;
|
|
4532
4543
|
const currentSchemaData = currentState.values || {};
|
|
4533
|
-
const isSectionValid = sectionValidate(originalSection, currentSchemaData, dispatch);
|
|
4544
|
+
const isSectionValid = sectionValidate(originalSection, currentSchemaData, dispatch, true);
|
|
4534
4545
|
if (!isSectionValid)
|
|
4535
4546
|
return;
|
|
4536
4547
|
const oldSchemaData = schemaData || contextSchemaData;
|
|
@@ -5164,6 +5175,10 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
|
|
|
5164
5175
|
// Stable ref for namespace so formHandle useMemo doesn't depend on the (possibly inline) function identity
|
|
5165
5176
|
const namespaceRef = useRef(namespace);
|
|
5166
5177
|
namespaceRef.current = namespace;
|
|
5178
|
+
// Stable refs so formHandle closure can access current mode and accordion setter without stale captures
|
|
5179
|
+
const modeRef = useRef(mode);
|
|
5180
|
+
modeRef.current = mode;
|
|
5181
|
+
const setExpandedSectionIndexRef = useRef(setExpandedSectionIndex);
|
|
5167
5182
|
// Track dirty (unsaved changes) per section for form handle validation
|
|
5168
5183
|
const sectionDirtyMapRef = useRef({});
|
|
5169
5184
|
const handleSectionDirtyChange = useCallback((sectionId, isDirty) => {
|
|
@@ -5225,33 +5240,52 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
|
|
|
5225
5240
|
};
|
|
5226
5241
|
return {
|
|
5227
5242
|
validate: async () => {
|
|
5228
|
-
|
|
5243
|
+
if (modeRef.current !== 'IntakeForm')
|
|
5244
|
+
checkNoUnsavedChanges();
|
|
5229
5245
|
const values = getValues();
|
|
5230
5246
|
let allValid = true;
|
|
5247
|
+
let firstInvalidIndex = null;
|
|
5231
5248
|
for (let i = 0; i < safeSections.length; i++) {
|
|
5232
5249
|
const section = safeSections[i];
|
|
5233
5250
|
const ns = getNamespace(section, i);
|
|
5234
5251
|
const sectionToValidate = ns ? namespaceSectionConfig(section, ns) : section;
|
|
5235
5252
|
const valid = sectionValidate(sectionToValidate, values, dispatch);
|
|
5236
|
-
if (!valid)
|
|
5253
|
+
if (!valid) {
|
|
5254
|
+
if (firstInvalidIndex === null)
|
|
5255
|
+
firstInvalidIndex = i;
|
|
5237
5256
|
allValid = false;
|
|
5257
|
+
}
|
|
5258
|
+
}
|
|
5259
|
+
if (!allValid && modeRef.current === 'IntakeForm' && firstInvalidIndex !== null) {
|
|
5260
|
+
setExpandedSectionIndexRef.current(firstInvalidIndex);
|
|
5238
5261
|
}
|
|
5239
5262
|
return allValid;
|
|
5240
5263
|
},
|
|
5241
5264
|
getFormData: () => getValues(),
|
|
5242
5265
|
validateAndGetData: async () => {
|
|
5243
|
-
|
|
5266
|
+
if (modeRef.current !== 'IntakeForm')
|
|
5267
|
+
checkNoUnsavedChanges();
|
|
5244
5268
|
const values = getValues();
|
|
5245
5269
|
const results = [];
|
|
5270
|
+
let firstInvalidIndex = null;
|
|
5246
5271
|
for (let i = 0; i < safeSections.length; i++) {
|
|
5247
5272
|
const section = safeSections[i];
|
|
5248
5273
|
const ns = getNamespace(section, i);
|
|
5249
5274
|
const sectionToValidate = ns ? namespaceSectionConfig(section, ns) : section;
|
|
5250
5275
|
const valid = sectionValidate(sectionToValidate, values, dispatch);
|
|
5251
5276
|
if (!valid) {
|
|
5252
|
-
|
|
5277
|
+
if (firstInvalidIndex === null)
|
|
5278
|
+
firstInvalidIndex = i;
|
|
5253
5279
|
}
|
|
5254
|
-
|
|
5280
|
+
else {
|
|
5281
|
+
results.push(buildSectionChanges(section, values, ns));
|
|
5282
|
+
}
|
|
5283
|
+
}
|
|
5284
|
+
if (firstInvalidIndex !== null) {
|
|
5285
|
+
if (modeRef.current === 'IntakeForm') {
|
|
5286
|
+
setExpandedSectionIndexRef.current(firstInvalidIndex);
|
|
5287
|
+
}
|
|
5288
|
+
throw new Error('Validation failed. Please fix the errors and try again.');
|
|
5255
5289
|
}
|
|
5256
5290
|
return results;
|
|
5257
5291
|
},
|