@@ -161,7 +161,7 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
161161 initialValue [ field . name ] = subFieldValues ;
162162 }
163163 } else {
164- // getDefaultValues and getPrefillSubFieldValues have a circluar dependency, resulting in one having to be used before defined.
164+ // getDefaultValues and getPrefillSubFieldValues have a circular dependency, resulting in one having to be used before defined.
165165 // As function declarations are hoisted this should not be a problem.
166166 // eslint-disable-next-line no-use-before-define
167167
@@ -213,46 +213,6 @@ export function getPrefillValues(fields, initialValues = {}) {
213213 return initialValues ;
214214}
215215
216- /**
217- * Preserves the visibility of nested fields in a fieldset
218- * @param {Object } field - field object
219- * @param {String } parentPath - path to the parent field
220- * @returns {Object } - object with a map of the visibility of the nested fields, e.g. { 'parent.child': true }
221- */
222- function preserveNestedFieldsVisibility ( field , parentPath = '' ) {
223- return field . fields ?. reduce ?. ( ( acc , f ) => {
224- const path = parentPath ? `${ parentPath } .${ f . name } ` : f . name ;
225- if ( ! isNil ( f . isVisible ) ) {
226- acc [ path ] = f . isVisible ;
227- }
228-
229- if ( f . fields ) {
230- Object . assign ( acc , preserveNestedFieldsVisibility ( f , path ) ) ;
231- }
232- return acc ;
233- } , { } ) ;
234- }
235-
236- /**
237- * Restores the visibility of nested fields in a fieldset
238- * @param {Object } field - field object
239- * @param {Object } nestedFieldsVisibility - object with a map of the visibility of the nested fields, e.g. { 'parent.child': true }
240- * @param {String } parentPath - path to the parent field
241- */
242- function restoreNestedFieldsVisibility ( field , nestedFieldsVisibility , parentPath = '' ) {
243- field . fields . forEach ( ( f ) => {
244- const path = parentPath ? `${ parentPath } .${ f . name } ` : f . name ;
245- const visibility = get ( nestedFieldsVisibility , path ) ;
246- if ( ! isNil ( visibility ) ) {
247- f . isVisible = visibility ;
248- }
249-
250- if ( f . fields ) {
251- restoreNestedFieldsVisibility ( f , nestedFieldsVisibility , path ) ;
252- }
253- } ) ;
254- }
255-
256216/**
257217 * Updates field properties based on the current JSON-schema node and the required fields
258218 *
@@ -283,22 +243,10 @@ function updateField(field, requiredFields, node, formValues, logic, config) {
283243 field . isVisible = true ;
284244 }
285245
286- // Store current visibility of fields within a fieldset before updating its attributes
287- const nestedFieldsVisibility = preserveNestedFieldsVisibility ( field ) ;
288-
289246 const updateAttributes = ( fieldAttrs ) => {
290247 Object . entries ( fieldAttrs ) . forEach ( ( [ key , value ] ) => {
291248 field [ key ] = value ;
292249
293- // If the field is a fieldset, restore the visibility of the fields within it.
294- // If this is not in place, calling updateField for multiple conditionals touching
295- // the same fieldset will unset previously calculated visibility for the nested fields.
296- // This is because rebuildFieldset is called via the calculateConditionalProperties closure
297- // created at the time of building the fields, and it returns a new fieldset.fields array
298- if ( key === 'fields' && ! isNil ( nestedFieldsVisibility ) ) {
299- restoreNestedFieldsVisibility ( field , nestedFieldsVisibility ) ;
300- }
301-
302250 if ( key === 'schema' && typeof value === 'function' ) {
303251 // key "schema" refers to YupSchema that needs to be processed for validations.
304252 field [ key ] = value ( ) ;
@@ -347,6 +295,7 @@ function updateField(field, requiredFields, node, formValues, logic, config) {
347295 isRequired : fieldIsRequired ,
348296 conditionBranch : node ,
349297 formValues,
298+ currentField : field ,
350299 } ) ;
351300 updateAttributes ( newAttributes ) ;
352301 removeConditionalStaleAttributes ( field , newAttributes , rootFieldAttrs ) ;
@@ -416,7 +365,7 @@ export function processNode({
416365
417366 if ( node . if !== undefined ) {
418367 const matchesCondition = checkIfConditionMatchesProperties ( node , formValues , formFields , logic ) ;
419- // BUG HERE (unreleated ) - what if it matches but doesn't has a then,
368+ // BUG HERE (unrelated ) - what if it matches but doesn't has a then,
420369 // it should do nothing, but instead it jumps to node.else when it shouldn't.
421370 if ( matchesCondition && node . then ) {
422371 const { required : branchRequired } = processNode ( {
@@ -500,14 +449,14 @@ export function processNode({
500449function clearValuesIfNotVisible ( fields , formValues ) {
501450 fields . forEach ( ( { isVisible = true , name, inputType, fields : nestedFields } ) => {
502451 if ( ! isVisible ) {
503- // TODO I (Sandrina) think this doesn't work. I didn't find any test covering this scenario. Revisit later.
504452 formValues [ name ] = null ;
505453 }
506454 if ( inputType === supportedTypes . FIELDSET && nestedFields && formValues [ name ] ) {
507455 clearValuesIfNotVisible ( nestedFields , formValues [ name ] ) ;
508456 }
509457 } ) ;
510458}
459+
511460/**
512461 * Updates form fields properties based on the current form state and the JSON schema rules
513462 *
@@ -549,7 +498,7 @@ function getFieldOptions(node, presentation) {
549498 } ) ) ;
550499 }
551500
552- /** @deprecated - takes precendence in case a JSON Schema still has deprecated options */
501+ /** @deprecated - takes precedence in case a JSON Schema still has deprecated options */
553502 if ( presentation . options ) {
554503 return presentation . options ;
555504 }
0 commit comments