[Vtigercrm-developers] extend Validation engine (Ajax)

Alan Lord alanslists at gmail.com
Thu May 26 09:21:17 GMT 2016


On 26/05/16 09:12, Preexo wrote:
> I would like to write an open extension which allows custom validation rules
> being set to individual fields.
>
> @Alan - Would this still be a good starting point?
> http://paste.ubuntu.com/10404014/

Not really - I ended up doing something different. I never found a good 
way to extend the Validation Engine.

In 5.4.0 we did have a very unobtrusive tool called JSValidation which 
worked well and could be written with little or no core code changes but 
the way JSValidation worked was totally incompatible with the v6 
architecture unfortunately. From my investigations it seems to be almost 
impossible in version 6 to do this.

> Did you achieve to attach the validation through the vtiger ValidationEngine
> without changing core files in the end? Like how did you apply your
> Vtiger_GlobalPhoneCheck_Validator_Js class to the vtiger? Through an
> extension?

No. In the end I think had to modify the uitype template (I did this for 
a few types). What I did was to add a new data parameter to the input tag

> <input id="{$MODULE}_editView_fieldName_{$FIELD_MODEL->get('name')}" type="text" class="input-large" data-validation-engine="validate[{if $FIELD_MODEL->isMandatory() eq true} required,{/if}funcCall[Vtiger_Base_Validator_Js.invokeValidation]]" name="{$FIELD_MODEL->getFieldName()}"

>  value="{$FIELD_MODEL->get('fieldvalue')}" data-fieldinfo='{$FIELD_INFO}' {if !empty($SPECIAL_VALIDATOR)}data-validator={Zend_Json::encode($SPECIAL_VALIDATOR)}{/if} data-uitype="{$FIELD_MODEL->get('uitype')}"/>

"data-uitype="{$FIELD_MODEL->get('uitype')}"

This adds the UIType integer to the input fields. I then have a custom 
JS library which looks for and deals with any custom validations.

Here is my globalPhoneCheck javascript function

http://paste.ubuntu.com/16703410/

> Currently my thoughts were going like this:
> - I add a hook to the user interaction of clicking the save button

What about editing a field in Detail or Summary view?

> - I request from my custom module if there are any validation rules for any

> of the fields in this module
> - I send those validation rules back to the front end
> - I validate the fields in my own javascript class
> - If it pass, I continue with the save event, if it fails I continue prevent
> the save
>
> Obviously my above way, I have implemented here:
> https://github.com/preexo/vtiger-checkduplicates-extension
> But it is not nice at all, it doesn't use the vtiger ValidationEngine and it
> can be bypassed when not using the standard front end.
>
> Just sharing my thoughts, if you have a better starting point for me, I
> would highly appreciate.
>
> The idea comes from looking at salesforce, there I can put a custom
> validation rule to any of the fields, it's what we want to do too.
>
>
> Alan Lord (News) wrote
>> With the help of my colleague Alan Bell, it transpires that the jQuery
>> ValidationEngine already supports Ajax validation inherently.
>>
>> I have the validation test and response working now but what is not
>> happening is an actual save event when the result is true... Yet.
>>
>>
>>
>> _______________________________________________
>> http://www.vtiger.com/
>>
>> Screenshot from 2015-02-25 14:31:28.png (12K)
>> <http://vtiger-crm.2324883.n4.nabble.com/attachment/15501/0/Screenshot%20from%202015-02-25%2014%3A31%3A28.png>
>> Screenshot from 2015-02-25 14:31:13.png (10K)
>> <http://vtiger-crm.2324883.n4.nabble.com/attachment/15501/1/Screenshot%20from%202015-02-25%2014%3A31%3A13.png>
>
>
>
>
>
> --
> View this message in context: http://vtiger-crm.2324883.n4.nabble.com/Vtigercrm-developers-extend-Validation-engine-tp15268p19126.html
> Sent from the vtigercrm-developers mailing list archive at Nabble.com.
> _______________________________________________
> http://www.vtiger.com/
>




More information about the vtigercrm-developers mailing list