Trigger Yii field validation onchange of another field

后端 未结 2 870
Happy的楠姐
Happy的楠姐 2021-01-19 00:54

I have two related fields in a Yii model. They are items_per and items_period.

items_per is an integer that reflects how many items to be processed

2条回答
  •  独厮守ぢ
    2021-01-19 01:30

    I created the following javascript function, which I manually call when changing specific fields. It performs ajax validation on all form elements.

    /**
     * @author marcovtwout
     * Force performing full ajax validation on given form.
     * @param Object $form jQuery form object
     */
    performFullAjaxValidation = function($form){
        var settings = $form.data("settings");
        $.each(settings.attributes, function () {
            this.status = 2; // force ajax validation
        });
        $form.data("settings", settings);
    
        // trigger ajax validation
        $.fn.yiiactiveform.validate($form, function (data) {
            $.each(settings.attributes, function () {
                $.fn.yiiactiveform.updateInput(this, data, $form);
            });
            $.fn.yiiactiveform.updateSummary($form, data);
        });
    }
    

提交回复
热议问题