Does vee-validate work with third-party UI components, e.g. of Primevue? - validation

I am using vee-validate v4.0, vue's (v3) components with TypeScript and UI components from Primevue and Ionic. Validation on simple input fields works fine:
<template>
...
<Field
v-slot="{ field }"
v-model="username"
:rules="isRequired"
name="username"
>
<IonInput
v-bind="field"
type="text"
/>
</Field>
<ErrorMessage
name="username"
class="error"
/>
...
</template>
<script lang="ts">
...
methods: {
isRequired (value: string) {
if (!value) {
return 'This field is required'
}
return true
}
}
...
</script>
Applying the same to Primevue's Dropdown element fails:
<Field
v-slot="{ field }"
v-model="campaign"
name="campaign"
:rules="isRequired"
>
<Dropdown
:options="campaigns"
option-value="id"
option-label="name"
placeholder="Choose a campaign"
v-bind="field"
/>
</Field>
<ErrorMessage
name="campaign"
class="error"
/>
Validation works as expected, but opening the Dropdown leads to error messages:
Do you know how this can be solved? Is there an example how vee-validate works with more complex fields like dropdown or multiselect elements?

This can be solved by listening on the input/change events and passing data between <Field> and (in this special case Primevue's) <Dropdown> as follows:
<Form v-slot="{ errors }" #submit="saveAndProceed()">
...
<Field
v-slot="{ field }"
v-model="campaign"
name="campaign"
value="value"
:rules="isRequired"
>
<Dropdown
:options="campaigns"
option-value="id"
option-label="name"
placeholder="Choose a campaign"
:model-value="field.value"
:class="{ 'p-invalid': errors.campaign }"
#input="field.onInput.forEach((fn) => fn($event.value))"
#change="field.onChange.forEach((fn) => fn($event.value))"
/>
<ErrorMessage
name="campaign"
class="error"
/>
</Field>
...
</Form>
Compare also with the following references for other events (onBlur etc.):
Vee-validate's Field reference
E.g., Primevue's Dropdown events

You need to add #update:modelValue="handleChange" to your dropdown:
<Field
v-slot="{ field, handleChange }"
v-model="campaign"
name="campaign"
:rules="isRequired"
>
<Dropdown
:options="campaigns"
option-value="id"
option-label="name"
placeholder="Choose a campaign"
v-bind="field"
#update:modelValue="handleChange"
/>
</Field>
<ErrorMessage
name="campaign"
class="error"
/>

<div class="col-6">
<Field
v-slot="{ field,handleChange }"
v-model="brand_name"
name="brand_name"
>
<div class="p-col-6">
<div class="p-inputgroup">
<Dropdown
:options="brands"
optionLabel="name"
optionValue="code"
:model-value="field.value"
placeholder="Select car brand"
#update:modelValue="handleChange"
/>
</div>
</div>
</Field>
</div>

Related

bootstrap multiselect box not displayed correctly

Im trynig to create a simple multiselect box but for some reason its not visible properly.
Here is my code:-
HTML
<input type="text" id="addRow" />
<input type="button" id="btn" value="Add" />
<form id="form1">
<div style="padding:20px">
<select id="chkveg" multiple="multiple"></select>
<br />
<br />
</div>
</form>
https://jsfiddle.net/04Lgnkqs/
After creating the select you should call the plugin on your select. something like this
$('#chkveg').multiselect();
Refer here

Do I need separate Struts Action for each form?

Do I need separate Struts action for each form?
Currently, one web page have two forms in jsp. I currently put all validation code in validate() in the Action class. The problem is that it appears the net result is that Form A will then be linked to Form B and vice versa since the validation code is inside the same Action class.
So am I correct that if I want the two forms to be validated independently, then I would require two separate Actions?
Form A:
<font color="red" size="2"><s:actionerror /> <s:fielderror /></font>
<s:form action="NewcreateUser" method="post">
<s:textfield type="text" name="form1filed" key="temp" size="11" label="Mobile_Num" required="true"></s:textfield><br />
<s:submit value="Continue" id="continueSignUp" validate="true"></s:submit>
</s:form>
Form B:
<font color="red" size="2"><s:actionerror /> <s:fielderror /></font>
<s:form action="NewcreateUser" method="post">
<s:textfield type="text" name="form2filed" key="formb" size="11" label="Mobile_Num" required="true"></s:textfield><br />
<s:submit value="Continue" id="continueSignUp" validate="true"></s:submit>
</s:form>
Here You can validate your fields,both form1filed,form2filed with the same Action class
NewcreateUser,And the NewcreateUser-validation.xml file looks like this,
<field name="form1filed">
<field-validator type="required" short-circuit="true">
<message key="form1filed Is Required" />
</field-validator>
</field>
<field name="form2filed">
<field-validator type="required" short-circuit="true">
<message key="form2filed Is Required" />
</field-validator>
</field>

bind radiobutton in mvc

Radio Button checked item should be true based on entry.isalbum value. Below is my View code..
#foreach(abc.Models.ddt entry in entrydetails)
{
#if(entry.isAlbum=="Album")
{
<input type="radio" id="c" name="isAlbum" checked="checked" value="Album" />
<label style="margin-right:10px" for="c"><span></span>Album</label>
}
<input type="radio" id="c1" name="isAlbum" value="Movies" />
<label style="margin-right:10px" for="c1"><span></span>Movies</label>
<input type="radio" id="c2" name="isAlbum" value="Single" />
<label style="margin-right:10px" for="c2"><span></span>Single</label>
</div>
}
}
foreach loop contain value stroed in database corresponding to Album, Movies or Single.
radio button checked should be true based on entry.isAlbum vale. How can we do this, please help to us? I have three radiobutton mention in above code. Radio Button checked will be true based on entry.Isalbum vale. Please help me
Try this:
<input type="radio" id="c" name="isAlbum" #if(entry.isAlbum=="Album"){<text>checked="checked"</text>} value="Album" />
<input type="radio" id="c1" name="isAlbum" #if(entry.isAlbum=="Movies"){<text>checked="checked"</text>} value="Movies" />
<input type="radio" id="c2" name="isAlbum" #if(entry.isAlbum=="Single"){<text>checked="checked"</text>} value="Single" />

Why doesn't this XML disable my joomla radio button?

<field name="name" type="radio"
class="btn-group"
label="label"
description="description"
default="0"
disabled = "true"
filter="raw">
<option value="0">No</option>
<option value="1">Yes</option>
</field>
How are you disable radio button with xml ?
One thing is that the disabled feature only works on option level, not for the whole field.
So you would need to set it like this:
<field name="name" type="radio"
class="btn-group"
label="label"
description="description"
default="0"
filter="raw">
<option value="0" disabled="true">No</option>
<option value="1" disabled="true">Yes</option>
</field>
However it doesn't work well together with the btn-group class. This is probably a Bootstrap bug.

Separation of forms & also drop down menu alteration when object selected

In the image provided of my registration page, I wish to put a vertical separator inbetween the form on the left to have another form on the right to be completed for the registration but I have no idea how to do it.
http://puu.sh/1FJIA
Also the second part of my question pertains to the drop down menu, how would I put an extra option other than #_usergroups that when selected will alter the drop down menu to change into a text box? Below is the coding used for the xml.
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="default"
label="COM_USERS_REGISTRATION_DEFAULT_LABEL"
>
<field name="spacer" type="spacer" class="text"
label="COM_USERS_REGISTER_REQUIRED"
/>
<field name="name" type="text"
description="COM_USERS_REGISTER_NAME_DESC"
filter="string"
label="COM_USERS_REGISTER_NAME_LABEL"
message="COM_USERS_REGISTER_NAME_MESSAGE"
required="true"
size="30"
/>
<field name="username" type="text"
class="validate-username"
description="COM_USERS_DESIRED_USERNAME"
filter="username"
label="COM_USERS_REGISTER_USERNAME_LABEL"
message="COM_USERS_REGISTER_USERNAME_MESSAGE"
required="true"
size="30"
validate="username"
/>
<field name="password1" type="password"
autocomplete="off"
class="validate-password"
description="COM_USERS_DESIRED_PASSWORD"
field="password2"
filter="raw"
label="COM_USERS_REGISTER_PASSWORD1_LABEL"
message="COM_USERS_REGISTER_PASSWORD1_MESSAGE"
required="true"
size="30"
validate="equals"
/>
<field name="password2" type="password"
autocomplete="off"
class="validate-password"
description="COM_USERS_REGISTER_PASSWORD2_DESC"
filter="raw"
label="COM_USERS_REGISTER_PASSWORD2_LABEL"
message="COM_USERS_REGISTER_PASSWORD2_MESSAGE"
required="true"
size="30"
/>
<field name="email1" type="email"
description="COM_USERS_REGISTER_EMAIL1_DESC"
field="id"
filter="string"
label="COM_USERS_REGISTER_EMAIL1_LABEL"
message="COM_USERS_REGISTER_EMAIL1_MESSAGE"
required="true"
size="30"
unique="true"
validate="email"
/>
<field name="email2" type="email"
description="COM_USERS_REGISTER_EMAIL2_DESC"
field="email1"
filter="string"
label="COM_USERS_REGISTER_EMAIL2_LABEL"
message="COM_USERS_REGISTER_EMAIL2_MESSAGE"
required="true"
size="30"
validate="equals"
/>
<field name="title" type="sql"
default="-None Listed-"
label="Select your University"
description="Select the University you are currently attending, if
it's not on the list then create it below"
query="SELECT title FROM #__usergroups WHERE ID > '8 ' "
required="true"
/>
<field
name="captcha"
type="captcha"
label="COM_USERS_CAPTCHA_LABEL"
description="COM_USERS_CAPTCHA_DESC"
validate="captcha"
/>
</fieldset>
</form>
1. Vertical separator:
you can use a hack i.e. create some fields which will output markup.
The idea here is to insert an extra
<div style='width:50%'>
before the first field;
Then a
</div><div style='width:49%;border-left:1px dashed black'>
where you want the separator
and finally a at the end.
Create three new spacer fields.
You can either insert properly escaped html directly:
<field type="spacer" name="splitterinit" label="<div>" />
or put the html as language constants in the language file:
SPLITTER_MID="</div><div style='width:49%;border-left:1px dashed black'>"
and simply use the constant in the .xml:
<field type="spacer" name="splittermid" label="SPLITTER_MID" />
2. Extra text option:
Easy: Simply add a text field below to allow the user to type in.
Harder: Create a custom element, there you can write php and make it
as you want it
3. A word of advice
Chronoforms features a user registration override that lets you define all the fields you want, and for sure you'll find more similar extensions on the JED
Also, all community solutions feature custom profiles.

Resources