Skip to content

Commit 4b50b61

Browse files
committed
feat: added support for argument 'trim' to required, removed isRequired
1 parent 72a82fb commit 4b50b61

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/libs/rules.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,18 @@ export default {
237237
},
238238

239239
/**
240-
* Rule: must be a value
240+
* Rule: must be a value - allows for an optional argument "whitespace" with a possible value 'trim' and default 'pre'.
241241
*/
242-
required: function ({ value }, isRequired = true) {
242+
required: function ({ value }, whitespace = 'pre') {
243243
return Promise.resolve((() => {
244-
if (!isRequired || ['no', 'false'].includes(isRequired)) {
245-
return true
246-
}
247244
if (Array.isArray(value)) {
248245
return !!value.length
249246
}
250247
if (value instanceof FileUpload) {
251248
return value.getFiles().length > 0
252249
}
253250
if (typeof value === 'string') {
254-
return !!value
251+
return whitespace === 'trim' ? !!value.trim() : !!value
255252
}
256253
if (typeof value === 'object') {
257254
return (!value) ? false : !!Object.keys(value).length

0 commit comments

Comments
 (0)