7 years ago
3
Topic

Hello there

I will leave here an example to make two or mode validations in the same field:

This example will use a seblod user email field with these native seblod settings (number 3 on forms and content types): required, availability

I need an additional validation to check if the field is filled with an valid email format.

So I will use the field Script (JS) in the end of my email field (stuff section) and write this code:

jQuery(document).ready(function ($) {
    object2 =
     {
         "email": {
	     		"regex": /^([A-Za-z0-9_\-\.'])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,10})$/,
			"alertText": "* This is not a valid email!"
		   }
      };

       $.validationEngineLanguage.allRules = $.extend( $.validationEngineLanguage.allRules, object2 ); //add an extra validation
});

Still in the stuff section, in the field Class (CSS) I must write this class: validate[required,custom[email]]


And It is Done!

Seblod uses this plugin to do validationhttps://github.com/posabsolute/jQuery-Validation-Engine (it is a good idea to take a look in this link)


If you need other validation objects you can make a seblod form with fields making all available kind of validations and take a look in the page source to have a list of all possible validations. Just look for "$.validationEngineLanguage.newLang"  and you will see all of them below.

In this same form you can see the fields classes (in the page source) to find out wich classes each validation is using.

Enjoy!




 

Get a Book for SEBLOD
1283 Posts
Bucklash
7 years ago
0
Level 1

Dantd!

I wish more Seblod users posted what they have learned/discovered or their tips and tricks like you did here..

nice!!

4229 Posts
Kadministrator
7 years ago
0
Level 1

Please copy/paste this into a manual, it an often asked question, thnx.

7 years ago
0
Level 1

Hello everybody,

First I would like to say I totally agree with you Bucklash!

Bad and good news...

The code above is not working due to a position (order of load) in javascript. The code is correct but I couldn´t make it work. However I found a turn-around 

using the field BeforeRender:

$regex = "/^([A-Za-z0-9_\-\.'])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,10})$/,";

$config['validation']['email_user_email'] = '"email_user_email":{"regex":'.$regex.'"alertText":"* This is not a valid email!"}';

I´ve put the regex expression in a separeted variable to avoid escape errors. The logic is the same and you still have to fill the class field like explained above.

TIP: You can use the code below to see all existing validations in a form (in before render field):

echo "<pre>";
print_r ($config['validation']);
echo  "</pre>";
die();


Get a Book for SEBLOD