Skip to content

Commit

Permalink
feat(gv-schema-form): implement writeOnly property support
Browse files Browse the repository at this point in the history
  • Loading branch information
gcusnieux authored and gaetanmaisse committed Jun 21, 2021
1 parent c1bcb94 commit 3b743c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/organisms/gv-schema-form-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class GvSchemaFormControl extends LitElement {
value: { type: Object, reflect: true },
skeleton: { type: Boolean, reflect: true },
hidden: { type: Boolean, reflect: true },
writeOnly: { type: Boolean, reflect: true },
};
}

Expand All @@ -63,7 +64,10 @@ export class GvSchemaFormControl extends LitElement {
}

isPassword() {
return this.control['x-schema-form'] && this.control['x-schema-form'].type != null && this.control['x-schema-form'].type === 'password';
return (
this.control.writeOnly === true ||
(this.control['x-schema-form'] && this.control['x-schema-form'].type != null && this.control['x-schema-form'].type === 'password')
);
}

getPlaceholder() {
Expand Down
2 changes: 2 additions & 0 deletions src/organisms/gv-schema-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export class GvSchemaForm extends LitElement {
this._ignoreProperties.push(key);
}
const isReadonly = this.readonly || control.readOnly === true;
const isWriteOnly = control.writeOnly === true;
const value = get(this._values, key);
return html`<gv-schema-form-control
.id="${key}"
Expand All @@ -250,6 +251,7 @@ export class GvSchemaForm extends LitElement {
.skeleton="${this.skeleton}"
.value="${value}"
?readonly="${isReadonly}"
?writeonly="${isWriteOnly}"
?required="${isRequired}"
?disabled="${isDisabled}"
?hidden="${isHidden}"
Expand Down
1 change: 1 addition & 0 deletions stories/organisms/gv-schema-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('S C H E M A F O R M', () => {
'disabled',
'hidden',
'readonly',
'writeonly',
];

const checkControl = (id, attributes = []) => {
Expand Down
7 changes: 7 additions & 0 deletions stories/resources/schemas/mixed.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@
"description": "Example for readonly",
"type": "string",
"readOnly": true
},
"writeonly": {
"title": "Write only field",
"default": "Should not read my value",
"description": "Example for writeonly",
"type": "string",
"writeOnly": true
}
},
"required": ["multiselect", "timeToLiveSeconds"]
Expand Down

0 comments on commit 3b743c6

Please sign in to comment.