question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: define validation messages in component

See original GitHub issue

First of all, thank you for sharing this great library!

As far as I can tell, you have to define error messages globally at the top level of your application. Is it possible to define them within the component? It doesn’t seem like they would be allowed to live within data.validations since vuelidate would produce errors. Could they somehow be defined alongside, maybe as data.validation_messages with keys matching data.validations?

Does this seem like a good idea? It would allow us to reuse field names in different components. Is there already someway to do this?

I see that there is a table of Component Props in the documentation with one of the fields being messages. Is this what I’m looking for? I’m not sure where these props are supposed to be used.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
dobromir-hristovcommented, Sep 15, 2017

OK so maybe I have to make this more clear: To init you usually have this:

// messages.js
export default {
	required: 'The {attribute} field is required!',
	min: 'The {attribute} field should be at least {min} characters.'
}



// app.js

import vuelidateErrorExtractor from 'vuelidate-error-extractor'
import template from './my/custom/template'
import messages from './messages.js'

Vue.use(VuelidateErrorExtractor, {
  templates,
  messages,
})

Now when ever you use the error extractor, all your messages will be used.

If you want to overwrite one of them you can do

<template>
	<form-group :validator="$v.form.username" label='Username' :messages="localMessages">
		<input type="text" name="username" v-model="form.username" @input="$v.form.username.$touch()">
	</form-group>
</template>

<script>
	import {required} from 'vuelidate/lib/validations'

	export default {
		data () {
			return {
				form: {
					username: '',					
				},
				localMessages: {
					required: 'You should really fill in the {attribute} field!'
				}
			}
		},
		validations: {
			form: {
				username: { required() }
			}
		}
	}
</script>
1reaction
vishaltripathi189commented, Feb 11, 2021

OK so maybe I have to make this more clear: To init you usually have this:

// messages.js
export default {
	required: 'The {attribute} field is required!',
	min: 'The {attribute} field should be at least {min} characters.'
}

Is This {min} still working? It was working for me in past but stopped working for some time. {attribute} is still working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Display Validation or Error Messages in Angular Forms
This guide covers how to display validation or error messages with Angular forms. It looks at both template-driven forms and reactive forms.
Read more >
Creating a Reusable Display for Validation Errors and ...
Lets now take a look at each of these validator methods defined in validator.ts. Each of the methods return either an object with...
Read more >
Move validation messages to the component class in reactive ...
In this video we will discuss, how to move validation messages to the component class. Healthy diet is very important for both body...
Read more >
Validating form input - Angular
Every time the value of a form control changes, Angular runs validation and generates either a list of validation errors that results in...
Read more >
Show Validation Error Messages for Reactive Forms in ...
We can define a reactive form within a component and check if the form is valid, but if there's an error, how do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found