How To Create Dynamically Textbox

Hello,

I need ta create dynamically some textBox in my view _form.

How can I do that ?

And in which action I must put the code ? On beforeRender maybe?

Thank

Nath

Can you be more specific about what you’re trying to achieve?

yes of course.

I have a exemple for what I would like to do in prado :

I think it would be more explicit as my explanation whith my bad english.




// retrieve as much row as it count in the table language

 $this->myLangues = ba_LangueRecord::finder()->findAllLangues();


        // Init the input texts for multilingual texts:

        foreach ($this->myLangues as $myLangue) {

            $myDiv = new TPanel();

            $myDiv->setID('nom_div_'.$myLangue->langue_id);


            $myTextbox = new TTextBox();

            $myTextbox->setID('nom_edit_'.$myLangue->langue_id);

            $myTextbox->setText(null);

            $myTextbox->setColumns(50);

            $myTextbox->setMaxLength(255);


            $myLabel = new TLabel();

            $myLabel->setForControl($myTextbox->getID());

            $myLabel->setText('* '.Prado::localize('nom').' ['.$myLangue->langue_nom.']');


            $myValidation = new TRequiredFieldValidator();

            $myValidation->setControlToValidate('nom_edit_'.$myLangue->langue_id);

            $myValidation->setText('*');

            $myValidation->setControlCssClass('validateField');

            $myValidation->setDisplay('Dynamic');

            $myValidation->setValidationGroup('saveGroup');


            $myDiv->Controls[] = $myLabel;

            $myDiv->Controls[] = $myTextbox;

            $myDiv->Controls[] = $myValidation;


            $this->nomPlaceHolder->Controls[] = $myDiv;

        }



Is it more clear for you ?

at this point, I just did that :




  protected function beforeRender($view) 

    { 

        

        if ($view=="update" || $view=="create"){

           

             $this->myLangues = BaLangue::model()->find();

             

           foreach ($this->myLangues as $myLangue) {

            $myTextbox = new CFormInputElement(array('size'=>45,'maxlength'=>45,'type'=>'textfield'),$form); 

            $view->setElements($myTextbox);

         }




but it doesn’t work

You need findAll() rather than find() if you’re looking to return all of the records in the table.

That aside, I’m still not sure what you’re trying to achieve with the code. You might want to go through the Yii guide, especially the section on forms.