Extend Yii.validation.js

Hi everyone.

How extend yii.validation.js without modify origional one.

Thanks.

Need use case on how and where you want to do this.

You can always add your own custom js and register as asset in your view, that can override the default functionality.

Thanks.

Excuse me for my bad english.

I want add validation like phone number validation mobile number validation and … to yii.validation.js, but in another js file. Like validation plugin for Jquery.

Thanks in advance.

First you can do one or all of the following to disable Yii client validation

  • Set param [font="Courier New"]enableClientValidation[/font] to [font="Courier New"]false[/font] at the ActiveForm or ActiveField level

  • Set param [font="Courier New"][font="Courier New"]validateOnChange[/font][/font] to [font="Courier New"]false[/font] at the ActiveForm or ActiveField level

  • Set param [font="Courier New"][font="Courier New"]validateOnSubmit[/font][/font] to [font="Courier New"]false[/font] at the ActiveForm or ActiveField level

Then you can add your own JQuery validation to your view by registering it as an asset or a separate js file:

For example in your view file:




$this->registerJs('path\to\custom.validation.js');



I dont want use another validation plugin. I want use yii.validation.js but add some validation like phone number validation.

In validation plugin for Jquery, It is possible to add some method to validation plugin in another js file.

Is it possible to add some method to yii validation plugin in another js file?

Thanks

Why are you only adding that validation in the js? You should be validating in both the frontend (js) and the backend (php).

I know.

php part is no problem.

my problem is in js part

You should be able to call a custom validation js in the end even if you do not want to disable yii validation and thus use both. Have you tried this?




$this->registerJs('path\to\custom.validation.js');



The custom.validation.js can contain $(’.input-class’).change event or something where .input-class can be a custom css class added to your active field input.