Change field display type at runtime

Questions and answers for designing and implementing forms in Servoy

Change field display type at runtime

Postby deezzub » Tue Feb 04, 2014 11:50 am

Is it possible to change the display type of a field from TEXT_FIELD to COMBOBOX at runtime? If yes, how? I tried solutionModel.getForm( formName ).getComponent( fieldName ), but I don't find something about that.
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany

Re: Change field display type at runtime

Postby sovanm » Tue Feb 04, 2014 12:27 pm

Hi,

Yes, it is possible to change the display type of an element at runtime.

Code: Select all
   // Get the form name
   var jsForm= solutionModel.getForm(<formName>);
   // Get the field by passing the name of the field
   var jsField = jsForm.getField('<fieldName>');
   // Check the display type
   if(jsField .displayType === JSField.TEXT_FIELD) {
      
      // Set the Display type
      jsField .displayType = JSField.COMBOBOX;
   }
   
   //Recreate the UI
   controller.recreateUI();


Another way to do this is by setting two fields overlapping eachother and adjusting the visibility of the element you want to show inside onRender event.

Hope this will help!

Thanks
Sovan
sovanm
 
Posts: 99
Joined: Fri Oct 28, 2011 1:55 pm
Location: Bhubaneswar, India

Re: Change field display type at runtime

Postby deezzub » Tue Feb 04, 2014 4:01 pm

sovanm wrote:
Code: Select all
   // Get the field by passing the name of the field
   var jsField = jsForm.getField('<fieldName>');



Of course, getField was it. I used it already, but I don't saw it earlier. Thanks, Sovan.
deezzub
 
Posts: 328
Joined: Tue May 28, 2013 3:02 pm
Location: Oldenburg, Germany


Return to Forms

Who is online

Users browsing this forum: No registered users and 9 guests