diff --git a/src/helpers/attributeParser.ts b/src/helpers/attributeParser.ts index 7bba61e..18f6659 100644 --- a/src/helpers/attributeParser.ts +++ b/src/helpers/attributeParser.ts @@ -160,7 +160,13 @@ export const parseJsonAttributes = ({ return finalAttributes; } catch (error) { console.error(error); - throw new Error("Error parsing new json_attrs. Original string: " + attrs); + if (error instanceof SyntaxError) { + throw new Error( + "Error parsing new json_attrs. Original string: " + attrs, + ); + } else { + throw error; + } } }; @@ -169,21 +175,18 @@ const evaluateAttributes = ({ values, fields, widgetType, + fallbackMode = true, }: { tagAttributes: any; values: any; fields: any; widgetType?: string; + fallbackMode?: boolean; }) => { - let newTagAttributes = {}; - - if (tagAttributes.json_attrs) { - newTagAttributes = parseJsonAttributes({ - attrs: tagAttributes.json_attrs, - values, - }); - } else if (tagAttributes.attrs) { - newTagAttributes = parseAttributes({ + let finalTagAttributes = {}; + let oldTagAttributes = {}; + if (tagAttributes.attrs) { + oldTagAttributes = parseAttributes({ attrs: tagAttributes.attrs, values, fields, @@ -191,9 +194,26 @@ const evaluateAttributes = ({ }); } + if (tagAttributes.json_attrs) { + try { + finalTagAttributes = parseJsonAttributes({ + attrs: tagAttributes.json_attrs, + values, + }); + } catch (error) { + if (fallbackMode && tagAttributes.attrs) { + finalTagAttributes = oldTagAttributes; + } else { + throw error; + } + } + } else if (tagAttributes.attrs) { + finalTagAttributes = oldTagAttributes; + } + return { ...tagAttributes, - ...newTagAttributes, + ...finalTagAttributes, attrs: undefined, json_attrs: undefined, }; diff --git a/src/spec/Form.spec.ts b/src/spec/Form.spec.ts index 3a4a4df..f9b2f67 100644 --- a/src/spec/Form.spec.ts +++ b/src/spec/Form.spec.ts @@ -3259,4 +3259,33 @@ describe("A Form", () => { const buttonWidget = form.findById("example_button") as Button; expect(buttonWidget.readOnly).toBeFalsy(); }); + it("Should be able to parse a specifically enabled button even though in the form is disabled, with json_attrs", () => { + const arch = `
+