Yii Car Service Items With Knockout.js

Hello everyone. I am trying to resolve Car Service Items on my project.

So here is what I need:

  • I have CarService model and CarServiceItems model

  • I want to have rendered CarServiceItems _form view on CarService _form view

  • I want to add multiple items, and POST everything (whole CarService and all of CarServiceItems models) that I can handle on controller CarService controller.

I know adding multiple Items should be implemented in Knockout.js, so can please anyone give at lease some example Knockout and Yii togather, not only Knockout examples, I already see them.

Thanks in advance!

Maybe you can use extension multimodelform instead.

See the demo code:

Group = CarService

Member = CarServiceItem

But you can’t use your CarServiceItems _form view, you have to use the Yii Formbuilder for the items instead.

If the CarServiceItem form elements are not to complex (widgets, …) this could work.

Wow Joblo,

Thanks a lot. You solved my problem. This is a really great extension, exactly what I need!!! Just to figure out how can I can use extension (http://www.yiiframework.com/wiki/361/simple-way-to-use-autocomplete-using-different-id-and-display-value/) in form builder. My CarServiceItem looks:

$carServiceItemsFormConfig = array(







            'type'=>'zii.widgets.jui.CJuiAutoComplete', //I want here to have extension above







Can you just tell me if this is possible? It means a lot to me if I could make this feature.

Thanks again, you really helped me!

Don’t know, if the custom autocomplete works.

The problem of (jquery) widget’s is always the same:

After cloning a element, the jquery plugin has to be executed for cloned element with the new id again.

So the has to be executed extra js-stuff after the ‘newId’ event.

Another developer (see the method comment of MultiModelForm::afterNewIdAutoComplete) did add the support for autocomplete with the js-code in the ‘afterNewIdAutoComplete’ method.

So first try the standard autocomplete widget for the car_part_component_id field.

You have to tell mmf to execute the afterNewIdAutoComplete js-code after cloning.




    'jsAfterNewId' => MultiModelForm::afterNewIdAutoComplete($formConfig['elements']['car_part_component_id']),



If this works, you can try with your extended autocomplete.

But no warrenty … sorry.

Please tell me, if it works.

If not, maybe you can alter the js-code of MultiModelForm::afterNewIdAutoComplete, but can be hard to find a solution …


I didn’t try to add jsAfterNewId, but I don’t see any problem with that, so I think that works. But for my custom autocomplete widget, unfortunately it doesn’t work, and I cannot spend so much time fixing plugin code, so I decide to implement my feature as dropdown list.