Making Yii 2 Client side validation work

Recently i have been working on Yii 2 for one of my clients. The application relies heavily on Ajax for loading different components and forms. Since there were forms, I had to use validation as well.

Yii 2 has made validation very simple. The server side validation worked perfectly, almost out of the box. I also had to add client side validation and despite everything being in order, the forms were not showing validation errors on input change.

Digging a little deeper i found out that i was using $this->renderPartial() to load the partials/forms which does not load the javascript validation libraries which are required to make the client side validation work. Fortunately, that is when i came upon the View::renderAjax() method that loads the libraries needed for client side validation.

So, all that is needed to make client side validation work on an ajax loaded page is to enable client validation like so:

And then rendering the form view like so:






Application developer, movie buff, occasional reader and a huge Manchester United fan.