Skip to content

Commit

Permalink
feat(gv-schema-form): add simple hidden field support
Browse files Browse the repository at this point in the history
  • Loading branch information
gcusnieux committed Aug 24, 2021
1 parent 7d670c8 commit 17b5e64
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/organisms/gv-schema-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ export class GvSchemaForm extends LitElement {
return false;
}
const condition = control['x-schema-form'][conditionKey];
if (typeof condition === 'boolean') {
return condition;
}
if (!Array.isArray(condition)) {
// condition isn't an array, ignore the condition
console.warn(`'${conditionKey}' attribute of 'x-schema-form' should be an array`);
Expand Down
3 changes: 3 additions & 0 deletions stories/organisms/gv-schema-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('S C H E M A F O R M', () => {
'multiselect',
'cron',
'disabled',
'hidden-with-condition',
'hidden',
'readonly',
'writeonly',
Expand Down Expand Up @@ -113,6 +114,7 @@ describe('S C H E M A F O R M', () => {
attributes: [{ name: 'foo', value: 'bar' }],
cron: '*/30 * * * * SUN-MON',
disabled: 'Simple Test',
hidden: 'not visible',
};
component.requestUpdate();

Expand All @@ -133,6 +135,7 @@ describe('S C H E M A F O R M', () => {
checkControl('attributes.0', { value: { name: 'foo', value: 'bar' } });
checkControl('cron', { value: '*/30 * * * * SUN-MON' });
checkControl('disabled', { value: 'Simple Test' });
checkControl('hidden', { value: 'not visible', hidden: true });
done();
}, 0);
});
Expand Down
9 changes: 8 additions & 1 deletion stories/resources/schemas/mixed.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"disabled": [{ "$def": "select" }, { "$eq": { "select": "a" } }]
}
},
"hidden": {
"hidden-with-condition": {
"title": "Hidden field if 'Simple select' is 'a'",
"type": "string",
"x-schema-form": {
Expand All @@ -167,6 +167,13 @@
]
}
},
"hidden": {
"title": "Hidden field",
"type": "string",
"x-schema-form": {
"hidden": true
}
},
"readonly": {
"title": "Readonly field",
"default": "Should not edit my value",
Expand Down

0 comments on commit 17b5e64

Please sign in to comment.