How to add custom field dymanically

Hi,

How to add field dynamically in yii, is it possible to field show dynamically in each category,I want to show

field dynamic for each category and also how to get details of the field and save in db.Please help me to add dymanic add field and get details.

Please tell is it possible in yii…

For Example:If i choose Category Cars & Bikes > Motorcycles Mean it show field Kms Driven,Brand Name etc related to bike catgory suppose i choose Apartment category mean it show No. of Rooms,Area Sq Ft related to apartment wise.

if you cant understand my english,plz ask me frankely sry for that.

You’re probably looking for entity-attribute-value.

Here’s an extension that claims to support it.

Alternatively, you could look into using a non-relational database such as MongoDB.

I was caught with a requirement same as you told have category, subcat and type in parent child relation to manipulate form fields to display user.

What I did is, loaded the full form with all the fields and than on change event of subcat called a JQuery that manipulate the form and show only the related fields to user its easy to manage in this way as on submit Yii leave the blank fields while adding or updating a model. for quick you may create an array that reflect the fields to show in catrgroies array(‘alpha’=>array(1.2), ‘beta’=>‘2,3’) and loop through the array in the js to hide or show fields.

or you can load the form with renderPartial() using ajax on the page.

if you need some code to more elaborate what I said let me know.

Hi,

Thanx For Your Reply,

I am also thinking that onchange when show all fields show and hide,I have some issue how to insert that field in db.

Ya i need example codeing,if You send some example coding mean its very helpful for me.

Hi,

Analysis that article eavactiverecord but i dont know what is the set rules using in Property "EavAttribute.setRules" is not defined Set rules column cant identify in EavAttribute table,I cant understand what is the Eavset and EavAttribute plz explain me

Hi,

Thanx for ur reply,Analysis that eavactiverecord i cant generate model extension eavactiverecord why?

And i cant understand eav attribute and eavset in yii.please explain me.

May I know where exactly you have problem?? controller or view?? and which code sample you need js?? check the following

var fieldsToShow = new Array();

                    var fieldIds = new Array('3','4','6','10','14','16','18','19','20','21','22','23','304','305', '306','307','308','309','310','311','312','313');


                    for(var j=1; j<fieldIds.length ; j++) {  


                     fieldsToShow["'"+fieldIds[j]+"'"] = new Array();


                    }

fieldsToShow[‘3’] = Array(’_country_id’, ‘_city_id’, ‘_manufacturar’,’_production_year’, ‘_length’, ‘_capacity’ );

fieldsToShow[‘anyindex’] = Array(‘your fields’);

and than may use switch case

switch (dropdownVal) {

                        case ( "3" ): //offshore marien vesles and boats


                                    var fieldsToShowArray = fieldsToShow['3'] ;


                                    


                                    for(var i =0; i<fieldsToShowArray.length; i++){


                                       


                                         $('#'+pagename+fieldsToShowArray[i]).closest('.col-md-6').toggle();


                                         


                                         $('#'+pagename+fieldsToShowArray[i]).closest('.col-md-3').toggle(true);


                                         


                                          $('#'+pagename+fieldsToShowArray[i]).closest('.form-group').toggle(true)


                                         


                                         


                                         


                                         


                                    }





                                    break;