Tabular Form in Ajax

How I can pass/use $form (ActiveForm) variable in a view that is rendered by action called in ajax request by another view (main page with add input button)

In the view rendered in ajax for inputs i have use:


<?= Html::activeInput($model,'attribute) ?>

<?= Html::error($model,'attribute) ?>

The ActiveForm configuration is


<?php $form = ActiveForm::begin([

    'fieldConfig' => [

	'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{endWrapper}\n{error}",

    ],

    //'enableClientValidation' => false,

    'enableAjaxValidation' => true,

    'validationUrl' => Url::to(['/trip/add-trip-validation'])

    

]); ?>

In the active field, on focusout, I see that the request to validationUrl start and the error is shown though is not managed by the validation action (I think that is yiiActiveForm that shows errors).

In the inputs (not active field) loaded in ajax on focusout no request start. The request in send only in form submission and though the response is json errors no one is shown.

Thank you

I try to reformulate my question…

The client validation is active only if I use ActiveField in ActiveForm?

Using an Html::activeInput I need to create my JavaScript? In this case there is some event like afterValidation?

AjaxValidation: when is usefull if there is yiiActiveForm.js? For the rules that need some serverside logic?

It is possible to pass $form from a view to a Controller via Ajax request? (for tabular inputs)

Thanks

Mattia

I solved appending a validation rule by javascript:

In the ajax response I append the html result and a jquery code like this:




jQuery("#add-trip").yiiActiveForm("add", {

                    "id": "trippoint-0-from",

                    "name": "[0]from",

                    "container": ".field-trippoint-0-from",

                    "input": "#trippoint-0-from",

                    "error": ".help-block.help-block-error",

                    "validate": function (attribute, value, messages, deferred, $form) {

                        yii.validation.required(value, messages, {"message": "Validation Message Here"});

                    }






<?php

$this->registerJs ('

$("#add_tpoint").click(function(){

        var lastIndex = $(".search_place:last").attr("data-id");

        lastIndex++;

        var label = "Tappa n."+$(".search_place").length;

        var _url = "'.Url::to(['/trip/get-trip-point-form']).'&index="+lastIndex+"&label="+label;

        // chiamata ajax

        $.ajax({

            url: _url,

            success:function(response){

                response = "<div id=\"tp_"+lastIndex+"\" class=\"tpoint\">"+response+"</div>";

                $("#t_point_stop div.panel-body").append(response);

                $("#t_point_stop").show();

                //add validation rule

                jQuery("#add-trip").yiiActiveForm("add", {

                    "id": "trippoint-"+lastIndex+"-from",

                    "name": "["+lastIndex+"]from",

                    "container": ".field-trippoint-"+lastIndex+"-from",

                    "input": "#trippoint-"+lastIndex+"-from",

                    "error": ".help-block.help-block-error",

                    "validate": function (attribute, value, messages, deferred, $form) {

                        yii.validation.required(value, messages, {"message": "Inserire un luogo"});

                    }

                });

            }   

        });

    });', $this::POS_READY );

?>



can you test renderAjax()?