Skip to content

Commit

Permalink
Merge branch 'fix/attrs-undefined-bug' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Sep 6, 2024
2 parents a6547a0 + 7f39e0d commit 987214b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/helpers/attributeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ const evaluateFieldComparison = ({
valueInObject === undefined &&
fields[fieldName].type !== "boolean" &&
fields[fieldName].type !== "many2one" &&
fields[fieldName].type !== "selection"
fields[fieldName].type !== "selection" &&
typeof expectedValue !== "boolean"
) {
return {
modifiedValueInObject: null,
Expand Down
23 changes: 23 additions & 0 deletions src/spec/Form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5773,4 +5773,27 @@ describe("A Form", () => {
expect(form.contextForFields.street).toBeDefined();
expect(form.contextForFields.street).toEqual({ active_test: false });
});
it("Should be able to parse attributes with an undefined char value and exist condition in attrs", () => {
const arch = `<form><group><alert colspan="4" name="alert1" alert_type="warning" title="Atenci&#243;n" text="Debes introducir un CUPS para iniciar tu oferta correctamente" attrs="{'invisible': [('cups', '!=', False)]}" json_attrs="{&quot;invisible&quot;: {&quot;rules&quot;: [{&quot;operator&quot;: &quot;!=&quot;, &quot;field&quot;: &quot;cups&quot;, &quot;value&quot;: false}], &quot;condition&quot;: &quot;AND&quot;}}"/>
<alert colspan="2" name="alert2" alert_type="info" title="Atenci&#243;n" text="alert2" attrs="{'invisible': [('cups', '=', False)]}" json_attrs="{&quot;invisible&quot;: {&quot;rules&quot;: [{&quot;operator&quot;: &quot;=&quot;, &quot;field&quot;: &quot;cups&quot;, &quot;value&quot;: false}], &quot;condition&quot;: &quot;AND&quot;}}"/>
</group><input type="char" name="cups" /></form>`;
const fields = {
cups: {
is_function: false,
size: 22,
string: "CUPS (*)",
type: "char",
views: {},
},
};
const form = new Form(fields);
form.parse(arch, { values: { cups: undefined } });
expect(form.type).toBe("form");
const alert1 = form.findById("alert1")!;
const alert2 = form.findById("alert2")!;
expect(alert1).toBeDefined();
expect(alert2).toBeDefined();
expect(alert1.invisible).toBeFalsy();
expect(alert2.invisible).toBeTruthy();
});
});

0 comments on commit 987214b

Please sign in to comment.