I want to add a string control on a form during run time when a button is clicked.
What I have tried so far:
run
form methodrunTimeControl_validate
form methodThe button has the following code in its clicked method:
void clicked()
{
FormBuildDesign design = Form.design();
FormBuildGroupControl formBuildGroupControl;
FormStringControl c;
FormControlType fC;
;
// c = addGroup.addControl(FormControlType::String, 'RunTimeControl');
c = ButtonGroup.addControl(fC::String, 'test');
c.label("New control");
formBuildGroupControl = formBuildDesign.control(addGroup.id());
}
I am getting error in the line c = ButtonGroup.addControl(fC::String, 'test');
Error: Enumeration doesn't exist
Firstly, replace fC::String
with FormControlType::String
.
Secondly, string controls cannot be added to button groups (ButtonGroup
control type) - add it to a normal Group
instead.
Thirdly, to avoid such issues as missing labels, etc., it makes sense to add - ignore this.element.lock();
before adding the control and element.unlock();
after updating its label.