← servoy magazine

[Tip] Grey descriptions of what a user can do within the dataprovider

  • Tips

by Marcel Trapman
www.it2be.com

Very slick, that grey explanation within a field that tells the user what to do... But how can you do this within your solution without too much work. Well this is quite easy. Below you will find a step by step desciption of how I do this:

a. First you attach a custom value to the dataprovider from the properties dialog in the dataprovider editor. In my case the 'note' dataprovider gets the custom value 'your note here'.
b. Now on the form where you place the note dataprovider you need to give the note element a name. In our case the element is named 'note' (original isn't it)
c. The next thing we need to make is a method 'checkNote' with the following script:

if (note && note !="your note here") //when the dataprovider note has any content but not the default/custom value
    elements.note.fgcolor = '#000000'; //make the text black
else //in any other case
{
    subject = "your note here"; //when the subject is empty then give it the default value again
    elements.note.fgcolor = '#999999'; //make the text grey
}

d. Now we can attach this method to the onRecordSelect event of the form and the onDataChange event of the element. onRecordSelect because we need to evaluate the content every time a record changes and onDataChange because any change to the dataprovider has to be evaluated.
e. Remember to check the ‘SelectOnEnter’ property so the complete content gets selected when you give focus to the field.

Cheers,

marcel