Appending tabular inputs and validating the form with ajax

Hi, I have a tough question

-I have a CActiveFrom with tabular inputs, configured with ‘enableAjaxValidation’ => true

-My goal is to dynamically add inputs when pressing on a ‘Add button’. This is easy with Chtml::ajax() and a partial

-My issue is that the form does not know that inputs have been added, because the new, ajax-appended inputs were not there when the form widget was created.

How do I re-init $(’#the-form’).yiiactiveform() so it gets to validate the full list of attributes, the old ones and the ajax-appended ones?

I tried to call $(’#the-form’).yiiactiveform() from the FireBug console with a different set of parameters, it breaks the validation by disabling it.

Please take note again that my aim is full ajax, both on validation and on appending new form fields.

Thanks

Hi,

I’m interested also.

Had many many tries but never a working solution.

I’m always failed on the same problem you described.

Did u get any answer?

I´m having this problem too.

No one on the forum had this type of problem and can help us?

My solution is:

-rewrite or patch(see below) Yiiactiveform.jquery.js to allow it to be ‘attched’ multiple times without duplicating event handlers. In you don’t, you’ll get multiple posts when validating, generally multiple event triggers

-register this JS:




$('body').ajaxSuccess(function(e, xhr, settings) {

// you may copy the portion below (from here to the #custom comment) from the 'standard' Yii generated JS

// you may also replace the CSS id selector with a class selector, so you cover multiple instances ofthe same form

    $('#my_form').yiiactiveform({'validateOnSubmit':true, 

//...

    

    });


// #custom


});



This will enable you to load Yii active forms partials with ajax, and still have clientValidation and ajaxValidation working

The patch unbinds change and keyup ebvents for controls, as well as submit event for the form.

If you want to manage this events, you’ll have to put your js at #custom, after yiiactiveform has been re-initialized

I’m attching the JS patch

3122

live_hook.yiiactiveform.jquery.js.patch.txt

I couldnt really do the validation of the newly added control using Ajax .

As i was doing clientValidation in the rest of the form , I just wrote a secondary script

to validate the newly added controls.

Just iterated their values and processed accordingly