Uncaught Error: [vee-validate] No such validator '1234567' exists - validation

I am using vee-validate to validate the register form and i have made the code as follows,
<form #submit.prevent="signUp()">
<div class="form-group" :class="{'has-error': errors.has('register.mobile_number') }" >
<input v-model="register.mobile_number" v-validate="register.mobile_number" data-vv-rules="required" required class="form-control" type="number" placeholder="Mobile Number">
</div>
<div class="form-group" :class="{'has-error': errors.has('register.email') }" >
<input v-model="register.email" v-validate="register.email" class="form-control" type="email" data-vv-rules="required|email" placeholder="Email">
</div>
<div class="form-group" :class="{'has-error': errors.has('register.password') }" >
<input v-model="register.password" v-validate="register.password" name="password" data-vv-rules="required" class="form-control" type="password" placeholder="Password">
</div>
<div class="form-group" :class="{'has-error': errors.has('register.confirm_password') }" >
<input v-model="register.confirm_password" v-validate="register.confirm_password" name="confirm_password" data-vv-as="password" data-vv-rules="required|confirmed:password" class="form-control" type="password" placeholder="Confirm Password">
</div>
<div class="modal-footer btn-center">
<button type="submit" class="btn btn-default">Sign Up</button>
</div>
</form>
And the script was:
export default {
data() {
return {
register: {
mobile_number: '',
email: '',
password: '',
confirm_password: '',
},
}
},
methods: {
signUp() {
this.$validator.validateAll().then((result) => {
});
axios.post(config.apiDomain+'/Home',this.register).then(response=>{
});
}
},
}
And also imported vee-validate in main.js as,
import VeeValidate from 'vee-validate';
Vue.use(VeeValidate);
But if we enter anything inside the input box, it is throwing error as
Uncaught Error: [vee-validate] No such validator '12312321' exists.
Whatever thing i enter inside any of the input box, it is showing the same error. Kindly help me to resolve this issue.

I had a similar error in VeeValidate 3, and the problem is that I forgot to include the rules in the import statement and then extend them like this:
import { required, email, integer, between } from 'vee-validate/dist/rules';
extend('required', required);
extend('email', email);
extend('integer', integer);
extend('between', between);
In case someone else does the same mistake.

The code is incorrectly specifying the validation rules. For example here:
<input v-model="register.mobile_number" v-validate="register.mobile_number" data-vv-rules="required" class="form-control" type="number" placeholder="Mobile Number">
The code is saying that the validation rule should be whatever is in register.mobile_number because of this: v-validate="register.mobile_number".
Instead, you should specify the name(s) of the validation rules to use.
<input v-model="register.mobile_number" v-validate="'required'" class="form-control" type="number" name="Mobile Number" placeholder="Mobile Number">
Note that I added name="Mobile Number" because either name or data-vv-name is required, and I removed data-vv-rules because it is deprecated.
All of this is covered directly in the basic example in the documentation.

Related

Cannot get updateOn 'blur' validation to work

I currently have a validation function to verify if the password and confirm password match. This seems to work just fine if I do not add updateOn blur, However when I add the blur it doesn't hit the match function which causes validation to not work. Not sure what I am doing wrong ?
Here is the function to check for matching passwords
```import { FormGroup } from '#angular/forms';
// custom validator to check that two fields match
export function MustMatch(controlName: string, matchingControlName: string) {
return (formGroup: FormGroup) => {
const control = formGroup.controls[controlName];
const matchingControl = formGroup.controls[matchingControlName];
if (matchingControl.errors && !matchingControl.errors.mustMatch) {
// return if another validator has already found an error on the matchingControl
return;
}
// set error on matchingControl if validation fails
if (control.value !== matchingControl.value) {
matchingControl.setErrors({ mustMatch: true });
} else {
matchingControl.setErrors(null);
}
};
}
```
Here is the HTML
``` <div class="card-block">
<p class="text-success" *ngIf="success">Your password has successfully been updated, you can now <a [routerLink]="['/login']">login</a> with your new password.</p>
<p class="text-danger" *ngIf="( resetPasswordForm.invalid && submitted)">Please complete all
required fields.</p>
<p class="text-danger" *ngIf="resetPasswordForm.controls['confirmPassword'].errors && resetPasswordForm.controls['confirmPassword'].errors.mustMatch">Passwords must match.</p>
<ng-container *ngIf="!success">
<p class="text-danger" *ngFor="let err of errorMessages">{{ err }}</p>
</ng-container>
<div class="form-group" [ngClass]="{'has-danger' :submitted && resetPasswordForm.controls.password.errors}">
<label class="form-control-label" for="password">New Password</label>
<input id="password" type="password" class="form-control" name="password" formControlName="password"
[ngClass]="{ 'is-invalid': submitted && resetPasswordForm.controls.password.errors}" required>
</div>
<div class="form-group" [ngClass]="{'has-danger' :submitted && resetPasswordForm.controls.confirmPassword.errors}">
<label class="form-control-label" for="confirmPassword">Confirm Password</label>
<input id="confirmPassword" type="password" class="form-control" name="confirmPassword" formControlName="confirmPassword"
[ngClass]="{ 'is-invalid': (submitted && resetPasswordForm.controls.confirmPassword.errors) ||
resetPasswordForm.controls['confirmPassword'].errors && resetPasswordForm.controls['confirmPassword'].error.mustMatch}" required>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary" >Reset Password</button>
<small class="text-muted"> <a [routerLink]="['/login']">Back to Login</a></small>
</div>
</form>
</section>```
Here is the component code
``` private createForm() {
this.resetPasswordForm = this.fb.group({
password: ['', Validators.required],
confirmPassword: ['', Validators.required]
}, {
validator: MustMatch('password', 'confirmPassword'), updateOn: 'blur' // verify that passwords match
});
}```
I would expect to see the error message "Passwords must match." after the user moves off the confirm password input box if they do not match. If they do match never seeing the error message
Seems that the code above does work, Not sure why I things were not working correctly but after many changes and reverting back it seems to now work

The POST method is not supported for this route. Supported methods: GET, HEAD.",…

I am having issues while using laravel resourceApi controller along with vue js i am creating and application where i am using vue and laravel i am posting a value to store method of my controller but it is saying the method is not allowded or 405 exception in the response. i need some help i am new to laravel and vue.
Here is my code
**UserController :**
public function store(Request $request)
{
return ['message' => 'i have your data'];
}
**Route:**
Route::apiResources(['user' => 'API\UserController']);
**Vue Code:**
<form #submit.prevent="createUser">
<div class="modal-body">
<div class="form-group">
<input
v-model="form.name"
placeholder="Enter name"
type="text"
name="username"
class="form-control"
:class="{ 'is-invalid': form.errors.has('name') }"
>
<has-error :form="form" field="name"></has-error>
</div>
<div class="form-group">
<input
v-model="form.email"
placeholder="Enter email"
type="email"
name="username"
class="form-control"
:class="{ 'is-invalid': form.errors.has('email') }"
>
<has-error :form="form" field="email"></has-error>
</div>
<div class="form-group">
<textarea
v-model="form.bio"
placeholder="Enter bio"
type="email"
name="username"
class="form-control"
:class="{ 'is-invalid': form.errors.has('bio') }"
/>
<has-error :form="form" field="bio"></has-error>
</div>
<div class="form-group">
<select
v-model="form.type"
placeholder="Enter bio"
name="type"
class="form-control"
:class="{ 'is-invalid': form.errors.has('type') }"
>
<option value>---Select User Role---</option>
<option value="admin">Admin</option>
<option value="user">Standard User</option>
<option value="author">Author</option>
</select>
<has-error :form="form" field="bio"></has-error>
</div>
<div class="form-group">
<input
v-model="form.password"
placeholder="Enter email"
type="password"
name="password"
class="form-control"
:class="{ 'is-invalid': form.errors.has('password') }"
>
<has-error :form="form" field="password"></has-error>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Create</button>
</div>
</form>
**Vue method :**
createUser() {
this.form.post("api/user");
}
error:
I have tried running your code in my program and all the code you mentioned above seems fine. Since you have not provided the code of createUser method so I think you might have done mistake while calling the api.
Please try the below code once in your axios post route.
methods:{
createUser(){
axios.post('/api/user/store', {
//keep your field here//
}).then(res => {
console.log(res)
}
}
}
Maybe there's an error in your post route in axios. It would be helpful if you show your createUser() method. But I'm guessing you have to do something as such to have your code run.
createUser()
{
axios.post('/api/user/store',{
//your fields and all
})
}
API Resource Routes doesn't Support the function for create and Edit i mean POST or PUT method. apiResource method automatically exclude these two routes(Create and Edit).If you want to store or update something, you may specify another route with its corresponding function or use resource routes rather then API resource route like as,
Route::resource(['user' => 'API\UserController']);
please go through the documentation https://laravel.com/docs/5.8/controllers#restful-partial-resource-routes
axios has a default path so if the get request is "/user" the path will be "http://localhost/client" but if you are making a call from another path "http://localhost/invoice" and the get request is "user" so axios will take the current path as base path "http://localhost/invoice/invoice/user" for this reason you must use "/user".
you can check the documentation: https://github.com/axios/axios#request-method-aliases
createUser(){
axios.post('/api/user',{
/* parameter */
})
}

how to display validations at angular2

I followed same sample with the code and tried to show validation when user removes the text in the input and show display messages.Unfortunately, when I remove the text field it does not show anything. Could you please check the code and tell me why I can not show the validation message ?
Regards
Alper
<label for="name">SA / Rentennummer 005 :</label>
<input type="text" class="form-control" id="name" required
[(ngModel)]="Input.name" name="name" #name="ngModel">
<div [hidden]="name.valid || name.pristine"
class="alert alert-danger">
name is required
</div>
In The typescript :
Input= { name:'Alper'};
form : FormGroup;
this.form = fb.group({
name : new FormControl({value: null}, Validators.compose([Validators.required, Validators.maxLength(100)]))
});
<form class="form-details" role="form" name="registrationForm" [formGroup]="userForm">
<div>
<div class="row input-label">
<label class="form-label" for="name">First name</label>
<input
[formControl]="form.controls['name']"
type="text"
class="form-control"
id="form"
name="form">
</div>
<div *ngIf="!form.controls['name'].valid">field is required</div>
</div>
</form>

Jquery Validate EqualTo Issue [duplicate]

This question already has an answer here:
Using jquery.validation equalTo( other ) to ensure "Sunday" is the inputted value
(1 answer)
Closed 8 years ago.
I have the following code
$("#emailForm").validate({
rules: {
"UserPasswordReset.EmailAddress": {
maxlength: 256,
email: true,
},
"UserPasswordReset.ConfirmEmailAddress": {
maxlength: 256,
email: true,
equalTo: "#UserPasswordReset.EmailAddress"
}
}
});
When I fill in the below form and press submit I says on the confirm box please enter the same value so I check, double check and for the love of god I check again, but still I get please enter the same value even though both fields are identical.
<div id="home" class="tab-pane active" role="tabpanel">
<div class="form-group">
<label class="col-sm-1 control-label no-padding-right" for="form-field-1-1"> Email</label>
<div class="col-sm-9">
<input id="emailaddress" class="col-xs-10 col-sm-5" type="text" value="" name="UserPasswordReset.EmailAddress" data-val-required="The EmailAddress field is required." data-val="true" autocomplete="off" placeholder="Please enter your email address">
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label no-padding-right" for="form-field-1-1"> Confirm </label>
<div class="col-sm-9">
<input id="confirm_email" class="col-xs-10 col-sm-5" type="text" value="" name="UserPasswordReset.ConfirmEmailAddress" autocomplete="off" placeholder="Please confirm your email address">
</div>
</div>
<button id="btnSaveEmail" class="btn btn-info pull-right" type="Submit" value="true" name="SaveEmailAddress"> Update Email </button>
</div>
What am I doing wrong here?
You ConfirmEmailAddress rule has
equalTo: "#UserPasswordReset.EmailAddress"
You don't have a control with id="UserPasswordReset.EmailAddress" (only one with id="emailaddress"). Change it to
equalTo: "#emailaddress"

how to can I use element name including dot for jQuery form valiator plugin

I am using jQuery and form validator plugin and it works fine except one page shown below.
HTML:
<form method="POST" enctype="multipart/form-data" id="frmReg" class="form-horizontal" novalidate="novalidate">
<input type="hidden" name="mode" id="mode" value="insert">
<input type="hidden" name="fileName" id="fileName">
<div class="control-group">
<label id="fileLabel" class="control-label">*File Name</label>
<div class="controls">
<input type="file" name="file" id="file" placeholder="Select file" required="required" class="valid">
</div>
</div>
<div class="control-group">
<label class="control-label">*Package Name</label>
<div class="controls">
<input type="text" name="id.appId" id="appId" placeholder="Type group ID" tabindex="0" class="valid">
</div>
</div>
<div class="control-group">
<label class="control-label">*Application Title</label>
<div class="controls">
<input type="text" name="appName" id="appName" placeholder="Type application name" class="valid">
</div>
</div>
<div class="control-group">
<label class="control-label">*Version</label>
<div class="controls">
**<input type="text" name="id.version" id="version" placeholder="Type version" tabindex="0" class="valid">**
</div>
</div>
<div class="control-group">
<label class="control-label">Description</label>
<div class="controls">
<textarea name="description" id="description" placeholder="Type description" class="valid"></textarea>
</div>
</div>
<div class="modal-footer">
<button aria-hidden="true" data-dismiss="modal" class="btn">Close</button>
<button class="btn btn-primary" type="submit">Submit</button>
</div>
</form>
JS:
$("#frmReg").validate({
ignore: "", //for hidden field
rules: {
version: {
required: true,
number: true
}
},
messages: {
version: {
required: "Enter version number",
number: "Decimal numbers only allowed."
}
}
});
**$("#frmReg").validate().element("#version");**
It works when I use 'version' as the input name but I have to use 'id.version' as input name rather than 'version' because of server-side framework. But when I use the name, the validation code always returns true, even when I type any special characters and alphabets.
How can I still use id.version for the element?
Your answer would be appreciated.
As per the documentation...
Fields with complex names (brackets, dots)
If your form consists of fields using names that aren't legal JavaScript identifiers, you have to quote those names when using the rules option
Simply put quotes around the name containing dots...
$("#frmReg").validate({
ignore: "", //for hidden field
rules: {
'id.version': {
required: true,
number: true
}
},
messages: {
'id.version': {
required: "Enter version number",
number: "Decimal numbers only allowed."
}
}
});
Working DEMO: http://jsfiddle.net/A2ZdL/

Resources