Reputation: 41
Does anybody have an example how can I add dynamically input fields in my qcubed project? Thanks!
Upvotes: 4
Views: 296
Reputation: 183
You can utilize the QPanel control to add controls on the fly. Just set its AutoRenderChildren attribute to true and set the dynamic controls parent to the QPanel.
// Instantiate our QPanel - this will render a div to contain our dynamic controls
// Note that the parent is $this. You will need to call render in your template
$this->pnl = new QPanel($this);
// Setting AutoRenderChildren so that the Panel will handle Rendering our dynamic
// controls.
$this->pnl->AutoRenderChildren = true;
// Creating a button with an Ajax action to create our dynamic controls
$this->btn = new QButton($this);
$this->btn->Text = "Add Control";
$this->btn->AddAction(new QClickEvent(), new QAjaxAction('btn_Click'));
protected function btn_Click($strFormId, $strControlId, $strParameter) {
// create the control and set its parent to the QPanel
$ctl = new QTextBox($this->pnl);
}
You can get more information on using QPanels on the QCubed examples website.
Upvotes: 1