Skip to content

Commit

Permalink
Fix required field validator not checking if field can be read by use…
Browse files Browse the repository at this point in the history
…r, before throwing required field error
  • Loading branch information
Fajfa committed Jul 8, 2024
1 parent 2151243 commit 301ae29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion client/web/compose/src/mixins/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,9 @@ export default {
if (r.deletedAt) {
return
}

const fields = p.module.fields
.filter(({ canUpdateRecordValue }) => canUpdateRecordValue)
.filter(({ canReadRecordValue, canUpdateRecordValue }) => canReadRecordValue && canUpdateRecordValue)
.map(({ name }) => name)

// cover the edge case where all fields are not updatable
Expand All @@ -397,6 +398,7 @@ export default {
}
}
})

this.errors.push(...errs.set)
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/js/src/compose/validators/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ function genericFieldValidator (field: ModuleField): ValidatorFn<Record> {
const { value } = arg0

if (field.isRequired) {
if (value === undefined || IsEmpty(value)) {
const isNewRecord = this.recordID === NoID
const canManageFieldValue = isNewRecord ? true : field.canReadRecordValue && field.canUpdateRecordValue

if ((value === undefined || IsEmpty(value)) && canManageFieldValue) {
return emptyErr
}
}
Expand Down

0 comments on commit 301ae29

Please sign in to comment.