Skip to content

Commit

Permalink
feat: added support for argument 'trim' to required, removed isRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
atharva3010 committed Mar 5, 2021
1 parent 72a82fb commit 4b50b61
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/libs/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,18 @@ export default {
},

/**
* Rule: must be a value
* Rule: must be a value - allows for an optional argument "whitespace" with a possible value 'trim' and default 'pre'.
*/
required: function ({ value }, isRequired = true) {
required: function ({ value }, whitespace = 'pre') {
return Promise.resolve((() => {
if (!isRequired || ['no', 'false'].includes(isRequired)) {
return true
}
if (Array.isArray(value)) {
return !!value.length
}
if (value instanceof FileUpload) {
return value.getFiles().length > 0
}
if (typeof value === 'string') {
return !!value
return whitespace === 'trim' ? !!value.trim() : !!value
}
if (typeof value === 'object') {
return (!value) ? false : !!Object.keys(value).length
Expand Down

0 comments on commit 4b50b61

Please sign in to comment.