how to set printable property at runtime

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

how to set printable property at runtime

Postby bobm » Mon May 07, 2012 9:42 pm

I have a report with several fields, one of them is an optional field with label.

The printable property for the label is currently set to Yes, but I would like to set it to No; then at runtime change it to Yes if the notes field has data.

Any suggestions on how to change the printable property at runtime when a field has data?
Bob Mezzadri
EyeCOR By Nteon
bobm
 
Posts: 81
Joined: Thu Dec 29, 2011 8:24 pm

Re: how to set printable property at runtime

Postby Joas » Tue May 08, 2012 10:48 am

You can change it using the solutionModel:
Code: Select all
var _jsForm = solutionModel.getForm("yourform");
_jsLabel = _jsForm.getLabel("yourlabel");
_jsLabel.printable = true;
forms.yourform.controller.recreateUI();

But I think it would be a lot easier to use a calculation as the dataprovider of the label:
Code: Select all
if (notes) {
   return "yourtext/yourimage";
}
return "";

Then it is just "shown" and "hidden" automatically.
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: how to set printable property at runtime

Postby bobm » Tue May 08, 2012 8:14 pm

This looks like it should work, however I need the label to print only if a different field (note) has data - if the field has no data then the label should not print

Code: Select all
var _jsForm = solutionModel.getForm("printForm");
var _jsLabel = _jsForm.getLabel("label");
var _jsNote = _jsForm.getComponent("note");

if (_jsNote != null){
_jsLabel.printable = true;
}


but this is not working.
Bob Mezzadri
EyeCOR By Nteon
bobm
 
Posts: 81
Joined: Thu Dec 29, 2011 8:24 pm

Re: how to set printable property at runtime

Postby omar » Thu Jun 21, 2012 12:55 pm

You forgot to recreate your form after changing it through the Solution Model. You should add:

Code: Select all
_jsForm.controller.recreateUI();
Intrasoft, Founder
Omar van Galen
omar@intrasoft.nl
+31-(0)6-21234586
Servoy Developer
omar
 
Posts: 377
Joined: Sat Feb 12, 2011 4:51 pm
Location: Intrasoft, The Netherlands


Return to How To

Who is online

Users browsing this forum: No registered users and 10 guests