« [News] Servoy Magazine maintenance | Main | [tip] 'Try' your statements and 'Catch' an exception »
October 05, 2005
[tip] use fields without a dataprovider attached
by Marcel Trapman
www.it2be.com
This is COOL, this is GREAT...
Didn't know this could be done but after 5 minutes of brainwashes I came up with this:
1. add a field to your form and set the dataprovider to none
2. name your field (example = 'fieldname')
3. create a method (example = 'changed_field')
4. add the following code to the method:
-----
elements.fieldname.selectAll();
application.output(elements.fieldname.getSelectedText());
-----
5. attach the method to the onFocusLost event
6. go to browse mode and test the stuff!
The only thing left is that you add your own datachanged check since this event, like onaction, won't work.
IMPORTANT: onFocusLost is potentially dangerous. I tested this but you have to build in all kinds of checks. It is better to do the check at your 'ok' or 'cancel' onAction events...
To be honest, I love my own tip :)
Cheers
BTW doesn't work on other than record-view (thanks for the correction Maarten) and not on password fields...
| Posted by IT2Be on October 5, 2005 at 05:47 AM in Tips | Permalink
Comments
Wow! Sounds perfect for a search form in a formInDialog... no more global fields or whatever... the perfect way to get fire and forget user data input!
Posted by: Nicola Gervasi | Oct 6, 2005 5:07:56 AM
Indeed Nicola, that's why I posted it.
However, you can forget about user input but the element won't. You have to set the content to "" when you open the form again. You do this in the following manner:
elements.fieldname.selectAll();
application.output(elements.fieldname.setSelectedText(""));
Posted by: Marcel Trapman | Oct 6, 2005 5:25:58 AM
Indeed Nicola, that's why I posted it.
However, you can forget about user input but the element won't. You have to set the content to "" when you open the form again. You do this in the following manner:
elements.fieldname.selectAll();
application.output(elements.fieldname.setSelectedText(""));
Posted by: Marcel Trapman | Oct 6, 2005 5:27:29 AM
Indeed Nicola, that's why I posted it.
However, you can forget about user input but the element won't. You have to set the content to "" when you open the form again. You do this in the following manner:
elements.fieldname.selectAll();
application.output(elements.fieldname.setSelectedText(""));
Posted by: Marcel Trapman | Oct 6, 2005 5:34:48 AM
Indeed Nicola, that's why I posted it.
However, you can forget about user input but the element won't. You have to set the content to "" when you open the form again. You do this in the following manner:
elements.fieldname.selectAll();
application.output(elements.fieldname.setSelectedText(""));
Posted by: Marcel Trapman | Oct 6, 2005 5:36:30 AM
Great Show!
Now I can trash lots of those globals.
Posted by: Miguel Ek Lopes | Oct 9, 2005 10:31:04 AM
Will this
elements.fieldname.selectAll();
elements.fieldname.setSelectedText("");
work on non-editable combo or it would work just on a text field?
I thought it would be better that servoy would add a text property for all the form objects that would return whatever contained in the field.
Posted by: Hameed | Oct 20, 2005 7:04:14 AM
Like you said Hameed, the combo box doesn't have text property so you can't select it.
Posted by: Marcel Trapman | Oct 20, 2005 8:55:50 AM