← servoy magazine

[tip] use fields without a dataprovider attached

  • Tips

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...

Comments (8)

Nicola Gervasi
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!
Marcel Trapman
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(""));
Marcel Trapman
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(""));
Marcel Trapman
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(""));
Marcel Trapman
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(""));
Miguel Ek Lopes
Great Show! Now I can trash lots of those globals.
Hameed
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.
Marcel Trapman
Like you said Hameed, the combo box doesn't have text property so you can't select it.