From 90a53cb4389a089d3c8a1aef3af25a2070d83f82 Mon Sep 17 00:00:00 2001 From: Pawan Kumar Date: Fri, 1 Mar 2024 17:45:54 +0530 Subject: [PATCH] fix: Radio group options not accessible (#31382) ## Summary by CodeRabbit - **New Features** - Improved accessibility by adjusting the focus behavior of radio buttons. - Enhanced feature flag handling for more granular control over new features. - **Refactor** - Optimized feature flag checks for better performance and readability. --------- Co-authored-by: Pawan Kumar --- .../validations/defaultOptionValidation.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/client/src/widgets/wds/WDSRadioGroupWidget/widget/config/propertyPaneConfig/validations/defaultOptionValidation.ts b/app/client/src/widgets/wds/WDSRadioGroupWidget/widget/config/propertyPaneConfig/validations/defaultOptionValidation.ts index 542e1b4f28..e7640d8491 100644 --- a/app/client/src/widgets/wds/WDSRadioGroupWidget/widget/config/propertyPaneConfig/validations/defaultOptionValidation.ts +++ b/app/client/src/widgets/wds/WDSRadioGroupWidget/widget/config/propertyPaneConfig/validations/defaultOptionValidation.ts @@ -5,6 +5,8 @@ export function defaultOptionValidation( props: any, _: any, ): ValidationResponse { + let { options } = props; + //Checks if the value is not of object type in {{}} if (_.isObject(value)) { return { @@ -33,6 +35,36 @@ export function defaultOptionValidation( }; } + if (!Array.isArray(options) && typeof options === "string") { + try { + const parsedOptions = JSON.parse(options); + + if (Array.isArray(parsedOptions)) { + options = parsedOptions; + } else { + options = []; + } + } catch (e) { + options = []; + } + } + + // @ts-expect-error type mismatch + const valueIndex = _.findIndex(options, (option) => option.value === value); + + if (valueIndex === -1) { + return { + isValid: false, + parsed: value, + messages: [ + { + name: "ValidationError", + message: `Default value is missing in options. Please update the value.`, + }, + ], + }; + } + return { isValid: true, parsed: value,