[enh] display errors if pattern doesn't match

This commit is contained in:
ljf 2021-08-27 20:17:34 +02:00
parent 985f55fd6b
commit 5557c57252
4 changed files with 14 additions and 3 deletions

View file

@ -103,6 +103,7 @@ export default {
const validation = this.validation
if (validation && validation.$anyError) {
const [type, errData] = this.findError(validation.$params, validation)
console.log(type, errData)
return this.$i18n.t('form_errors.' + type, errData)
}
return ''

View file

@ -17,6 +17,7 @@
</template>
<script>
export default {
name: 'InputItem',
@ -25,7 +26,6 @@ export default {
autocomplete_: (this.autocomplete) ? this.autocomplete : (this.type === 'password') ? 'new-password' : null
}
},
props: {
value: { type: [String, Number], default: null },
id: { type: String, default: null },
@ -38,6 +38,7 @@ export default {
step: { type: Number, default: null },
trim: { type: Boolean, default: true },
autocomplete: { type: String, default: null },
pattern: { type: Object, default: null },
name: { type: String, default: null }
}
}

View file

@ -84,7 +84,7 @@ export function formatYunoHostArgument (arg) {
if (!arg.help) {
arg.help = 'good_practices_about_admin_password'
}
arg.example = '••••••••'
arg.example = '••••••••••••'
validation.passwordLenght = validators.minLength(8)
}
},
@ -99,6 +99,7 @@ export function formatYunoHostArgument (arg) {
if (!isNaN(parseInt(arg.max))) {
validation.maxValue = validators.maxValue(parseInt(arg.max))
}
validation.numValue = validators.numeric
}
},
{
@ -192,6 +193,12 @@ export function formatYunoHostArgument (arg) {
else if (field.component !== 'CheckboxItem' && arg.optional !== true) {
validation.required = validators.required
}
if (arg.pattern) {
// validation.pattern = validators.helpers.withMessage(arg.pattern.error,
validation.pattern = validators.helpers.regex(arg.pattern.error, new RegExp(arg.pattern.regexp))
}
// field.props['title'] = field.pattern.error
// Default value if still `null`
if (value === null && arg.default) {
value = arg.default

View file

@ -175,11 +175,13 @@
"githubLink": "Url must be a valid Github link to a repository",
"name": "Names may not includes special characters except <code> ,.'-</code>",
"minValue": "Value must be a number equal or greater than {min}.",
"maxValue": "Value must be a number equal or lesser than {min}.",
"notInUsers": "The user '{value}' already exists.",
"number": "Value must be a number.",
"passwordLenght": "Password must be at least 8 characters long.",
"passwordMatch": "Passwords don't match.",
"required": "Field is required."
"required": "Field is required.",
"pattern": "{type}"
},
"form_input_example": "Example: {example}",
"from_to": "from {0} to {1}",