Invoke client side validation on link click

Is there a way to trigger client side form validation on link click?

I have a from with one standard non ajax submit button, and one ajax link.

Submit button does what submit button does normaly. Sends data to a controllerAction1 that does server side validation, does some math on data and returns result.

Ajax link gathers form data and sends it to controllerAction2 that does server side validation and saves data to database.

Whole server side magic is working fine, but what i can’t figure out (and i’m googleing for 2 days now) is how to trigger client side validation when ajax link is clicked.

I tried using “yiiActiveForm(‘validate’)” in js but it is not triggering anything.

Only thing that triggers validation is “yiiActiveForm(‘submitForm’)” which works fine when form data is not good, but once it’s good (passes valdiation), form gets submited (like you clicked on submit button) which i don+t want…

This is my js:


function handleAjaxLink(e) {


	e.preventDefault('#form');


	var

		$link = $(e.target),

		callUrl = $link.attr('href'),

		formId = $link.data('formId'),

		ajaxRequest;


	if($('#form').yiiActiveForm('submitForm') == true)

	{

		ajaxRequest = $.ajax({

			type: "post",

			dataType: 'json',

			url: callUrl,

			data: (typeof formId === "string" ? $('#' + formId).serializeArray() : null)

		});

	}

	


}

I’m having exactly the same problem as Ljudotina.

Is there already a solution for this ?

m





    

    $("form").on("submit", function(event) {

        event.preventDefault();

        var $form = $(this);

        if ($form.data('yiiActiveForm').validated)

        {

            enviarForm($form, url);


        }

        else {

            //wrong form not submit

        }


    });




//send form via ajax

function enviarForm($form, url, modal) {

    $.ajax({

        type: 'post',

        url: url,

        data: $form.serialize(),

        success: function(datos) {

            //server validation errors

            if ($(datos).find(".has-error").length)

            {

                //reload form

                modal.find(".modal-body").html(datos);

            }

            else {

                //real success 

                modal.modal('hide');

            }

        },

        error: function(datos) {

            modal.find(".modal-body").html(datos);

        }

    });

}