Use vee-validate flags with Vuetify errors.collect - vuetify.js

I am using Vee Validate with Vuetify like this:
<v-text-field
v-model="email"
type='email'
required
v-validate="'required|email'"
:error-messages="errors.collect('email')"
label="E-mail"
data-vv-name="email"
ref="email"
required
></v-text-field>
I want to use some field flags shown in the docs like this:
<span v-show="errors.has('email') && fields.email.touched">{{ errors.first('email') }}</span>
I want to use the built in Vuetify form errors since they look nice but can not seem to get the flags to work. I have tried:
:error-messages="errors.collect('email') && fields.email.touched"
This clearly is not correct. Any ideas?
Edit
I have added a code pen example, you will notice that as soon as you start typing in the email field you get an error in the confirm email field. What I am trying to do is only show the error if the field has an error and has been touched/changed.
https://codepen.io/tjquinn/pen/gKrVdX?&editors=101

Have you tried to rename your fields bag when adding VeeValidate to Vue in your main.js ? Sometimes conflicts happen whit global name fields.
I do it this way, in my main.js :
Vue.use(VeeValidate, {fieldsBagName: 'formFields'})
and in my code I add the prop data-vv-scope="myFormName" and access it like this :
this.formFields['$myFormName']['keyName'].touched

Related

HTML in vuetify hints

Previously (I thought?) it was possible to put HTML into vuetify hints but for me this is no longer working. For example, in one of my components I have:
<v-checkbox
v-model="create"
label="Nice label"
persistent-hint
hint="<span class="red--text">Red hint</span>"
/>
This hint used to display in red but now I see the full HTML code. Has something changed or am I doing something wrong?
In the Vuetify forum, MajesticPotatoe pointed me towards the bug report https://github.com/vuetifyjs/vuetify/issues/9647. This gave the following slots workaround, which works in my code:
<v-checkbox
v-model="create"
label="Nice label"
persistent-hint
hint="<span class="red--text">Red hint</span>"
>
<template v-slot:message="{ message, key }">
<span v-html="message"></span>
</template>
</v-checkbox>
It seems that this used to work without slots before the patch https://github.com/haggys22/vuetify/commit/f0d5edd7ddf7e01ba057b7f3d14604199b6db68d was merged.
behaviour changed from 1.5.19 to 1.5.20
1.5.19 (and before) treats html tags as expected
1.5.20, 1.5.21 treat html tags as simple text
'hint' is the 'string' type so you can't add HTML tags. Here is the screenshot from documentation: https://prnt.sc/qlag61
So, I think you can apply red color from CSS / SCSS using this class name '.v-messages__message' if you really need red color in hint.

Passing a custom event in a Laravel Blade View

I have a PHP blade file and I have a list of components working as they but can't seem to pass in a custom event in the kebab style casing the documentation mentions .
Blade template
<div id="app">
<Shop
:active-tab="activeTab"
#show-product-modal="handleShowProductModal"
>
</Shop>
</div>
Even the #show-product-modal color syntax in my text editor shows something is off but I can't tell what the issue is here. I've even tried camel casing it but that doesn't do it either. However, if i changed it to 1 word , like "#showitnow", it works fine.
When using VueJS you can't use kebab case for listening to component events. Instead your blade template should read:
<div id="app">
<Shop
:active-tab="activeTab"
#showProductModal="handleShowProductModal"
>
</Shop>
</div>

Custom required error message

I have required in my input element and I want to set custom error message there.
this works:
oninvalid="this.setCustomValidity('custom error')"
But I want to read that error message from resources which is in json file. I'm using i18n and ng2-translate which works fine if I'll do:
<span>{{'General.EmptySearch' | translate }}</span> it displays my error message.
so If I'll do that:
oninvalid="this.setCustomValidity('{{'General.EmptySearch' | translate }}')"
it says
Binding to event property 'oninvalid' is disallowed for security reasons, please use (invalid)=...
If 'oninvalid' is a directive input, make sure the directive is imported by the current module.
ok I'll change it. I'm doing that:
(invalid)="this.setCustomValidity('{{'General.EmptySearch' | translate }}')"
error is:
Got interpolation ({{}}) where expression was expected at column 24 in [this.setCustomValidity('{{'General.EmptySearch' | translate }}')]
What's wrong?
Here is my form:
int .ts file
searchval: FormGroup;
ngOnInit() {
this.searchval = new FormGroup({
Search: new FormControl('')
});
}
and html
<form (ngSubmit)="onSubmit(searchval)" [formGroup]="searchval">
<input type="text" class="form-control" required formControlName="Search" placeholder="{{ 'General.Search' | translate }}">
<button type="submit"></button>
</form>
OK, so you are using the model-driven form syntax.
Check out the official doc on form validation. It shows how to do form validation the proper way. It ALSO shows how to have validation messages in your code (vs in your template), which is what your question was about. Once your validation messages are in your code, you'll have no problem translating them.
Side note: I'm really curious why you wanted to validate your fields watching the (invalid) DOM event. I've never seen it done that way.

Vue.js validator evaluate old value on v-model when changed by javascript instead of typing

I am now getting trouble by the following code.
<input type="text" v-validate:startdate="['required']" v-model="current.start_at">
<date-picker :model.sync="current.start_at"></date-picker>
The problem is that the required validation works with the old value instead of new value of current.start_at when I change start_at on date-picker.
So, for example, instead of 01/01/2001, it still keeps 01/01/200 when validate with required, so it makes me mad.
I hope to get a solution about it.
Please help me!

Using Joomla 1.7 generic categories functions

Since 1.6, I believe, there's a generic way to use 'categories' in your own created components. The default Joomla components also use this. For example: the contacts, newsfeeds and weblinks components all use the generic com_categories functionality to achieve categorized content.
Currently I'm creating a component which also has categories so I'd like to use the generic Joomla category functions to achieve this.
The status: Currently I've got the following:
I've got a submenu 'categories' in my component which links to the generic categories component which some extra options. The options are there so the page will be redirected back to my component on save. This was pretty easy! But..
My problem: Now I'd like to add specific fields to my category, let's say: 'Category Moderator'.
So I've walked to the code of com_categories and in the following file 'administrator\components\com_categories\models\category.php' there is code (line 270) to look for specific component code, like the following:
// Looking first in the component models/forms folder
$path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/models/forms/$name.xml");
So the components looks (in my case) in the folder: administrator/components/mycomponent/models/forms/category.xml for specific component info.
Now, in the default category.xml of com_categories there's information about the edit screen, like the following:
<field
name="title"
type="text"
label="JGLOBAL_TITLE"
description="JFIELD_TITLE_DESC"
class="inputbox"
size="40"
required="true"/>
So the title of the category is apparantly required..
So I thought I add a line to this file:
<field
name="moderator"
type="text"
label="JGLOBAL_MODERATOR"
description="JFIELD_MODERATOR_DESC"
class="inputbox"
size="40"
required="true"/>
Except that's not enough to add the input..
So I've looked in the administrator/components/com_categories/views/category/edit.php template for hints, how to achieve this. But there's no code to add specific inputs for my component (or I'm wrong ;))..
Fields are added pretty specific like:
<li><?php echo $this->form->getLabel('title'); ?>
<?php echo $this->form->getInput('title'); ?></li>
I've also looked if I can overide the edit.php somehow, but unfortunately I haven't found it..
Short: Anyone knows how to add generic fields to the category edit page?
You can do it by using plugins ( you can take a look at the built-in user profile plugin for an example: /plugins/user/profile ). But if you want to add a "Category Moderator", I think you could achieve it using ACL.

Resources