saBootstrapValidator in Angular

See All Questions HereCategory: AngularJS version (1.8.x)saBootstrapValidator in Angular
toti1972 asked 2 months ago

Hi,
I’m using forms with¬†saBootstrapValidator and I’m trying to validate if an email exists through an ajax call to server. This is my validator array. Even when I use an email that is valid (in console it appears the message) the forms show the error message saying that the mail already exists. Any idea of what is bad in the validator?

validatorOptions = {
        fields: {
            user_mail: {
                validators: {
		    emailAddress: {
                        message: 'The value is not a valid email address'
                    },
                    notEmpty: {
                        message: "Please enter user's email"
                    },
		    callback: {
			message: 'Mail already exists in database',
			callback: (value, validator, $field) => {
							
			// Parameters obj-
			var fd = new FormData();
			fd.append('id',this.userId);
			fd.append('email',JSON.stringify(value));
			fd.append('token',this.token);
		
			return this.http.post ( artecsoft_config.rest.user.mailexists, fd )
			.map((response: Response) => {
				// login successful if there's a jwt token in the response
				let mailexists = response.json() && response.json().content && response.json().content.mailexists;
				let mailiscorrect = !mailexists;
				console.log('Mail is correct?');
				console.log(mailiscorrect);
				return mailiscorrect;
			})
			.subscribe(
				data => {
					if (!data) 
						console.log('Mail already exists');
					else
						console.log('Mail is correct');
					return data
				},
				err => {
					console.log(err);
				}, 
				() => { 
					console.log('done');
				}
			);
														
		}

...

Thank you

0 Answers
MyOrange Staff answered 2 years ago

[dwqa-list-questions]

Leave a Reply