Monday, September 12, 2011

Servoy TIP: Changing A Form's Style - LIVE

I had a need the other day to change the style that was displaying on a form. My first thought was to just change all the object properties via scripting (a HUGE pain!). But, with the help of the SolutionModel (and controller.recreateUI() - in version 5.2+) - it was a snap.

Let's say you have two styles: "defaultStyle" and "fancyStyle" defined in your resources. If you use this code:

var myForm = solutionModel.getForm(controller.getName());
myForm.styleClass = "fancyForm";
Done! Be careful here - depending on how you designed your styles - things could get "wonky" (margins are the big culpret)... but man, did I mention how much I LOVE this tool?!


Ashutos said...

Hi Bob,

Thanks for your tip . Are the "defaultStyle" and "fancyStyle" are style sheets. If through coding we are changing the style sheets then after reopening the solution then the forms are reverted back to there original style sheets.


Bob Cusick said...


Yes, that's right. Changes with the solutionModel don't persist - they are active only for the current session. If you want to change a style on the form definition - then you need to do it in Servoy Developer.

THANKS for your comment!

Web Analytics