@rjsf/utils
Version:
Utility functions for @rjsf/core
30 lines • 1.03 kB
JavaScript
/**
* Generates bracketed names
* Example: root[tasks][0][title]
* For multi-value fields (checkboxes, multi-select): root[hobbies][]
*/
export const bracketNameGenerator = (path, idPrefix, isMultiValue) => {
if (!path || path.length === 0) {
return idPrefix;
}
const baseName = path.reduce((acc, pathUnit, index) => {
if (index === 0) {
return `${idPrefix}[${String(pathUnit)}]`;
}
return `${acc}[${String(pathUnit)}]`;
}, '');
// For multi-value fields, append [] to allow multiple values with the same name
return isMultiValue ? `${baseName}[]` : baseName;
};
/**
* Generates dot-notation names
* Example: root.tasks.0.title
* Multi-value fields are handled the same as single-value fields in dot notation
*/
export const dotNotationNameGenerator = (path, idPrefix, _isMultiValue) => {
if (!path || path.length === 0) {
return idPrefix;
}
return `${idPrefix}.${path.map(String).join('.')}`;
};
//# sourceMappingURL=nameGenerators.js.map