Skip to content

Commit

Permalink
Refactor restFormField omit logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ghsolomon committed Feb 9, 2024
1 parent 04ce3a7 commit 8187091
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions desktop/cmp/rest/impl/RestFormField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@ export const restFormField = hoistCmp.factory({
model: uses(RestFormModel),

render({model, editor, ...props}) {
const {field, omit} = editor,
const {field} = editor,
fieldModel = model.getFormFieldModel(field),
fieldVal = fieldModel.value;

// Skip fields if explicitly requested via `omit`, or if they are a) empty and b) readonly
// when c) adding a record. No point in showing as they are not populated (nor are they
// expected to be), and they can't be edited - e.g. `dateCreated` and `lastUpdated`.
if (
omit === true ||
(isFunction(omit) && omit(fieldVal, model)) ||
(isNil(fieldVal) && fieldModel.readonly && model.isAdd)
) {
return null;
}
// Unless otherwise specified, omit fields if they are a) empty and b) readonly when c)
// adding a record. No point in showing as they are not populated (nor are they expected to
// be), and they can't be edited - e.g. `dateCreated` and `lastUpdated`.
const omit = editor.omit ?? (isNil(fieldVal) && fieldModel.readonly && model.isAdd);

if (omit === true || (isFunction(omit) && omit(fieldVal, model))) return null;

let config = assign({field, flex: 1}, editor.formField);

Expand Down

0 comments on commit 8187091

Please sign in to comment.