Fix optional fields are unexpectedly set to be required (#142)

This commit is contained in:
Quang Lam 2020-02-16 21:19:26 -06:00 committed by GitHub
parent 1299ab9156
commit 758072395e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,20 +10,20 @@ const kits = {
return null;
},
url: (val, maxLength, fieldName) => {
if (!isUrl(val)) {
if (val && !isUrl(val)) {
return '{fieldName} is not valid.'.replace('{fieldName}', fieldName);
}
return null;
},
// accept link without protocol prefix
lessStrictUrl: (val, _, fieldName) => {
if (!isUrl(val) && !isUrl(`http://${val}`)) {
if (val && !isUrl(val) && !isUrl(`http://${val}`)) {
return '{fieldName} is not valid.'.replace('{fieldName}', fieldName);
}
return null;
},
licenseKey: (val, ruleVal, fieldName) => {
if (!isValidLicenseKey(val)) {
if (val && !isValidLicenseKey(val)) {
return '{fieldName} is not valid.'.replace('{fieldName}', fieldName);
}
return null;
@ -34,6 +34,8 @@ const validate = (changes, rules) => {
const newChanges = { ...changes };
Object.keys(changes).forEach((key) => {
if (key.endsWith('Error')) return;
let err = null;
const val = newChanges[key];