Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Tip - Required Fields Different Backgroun Color

Status
Not open for further replies.

jimoo

Programmer
Jun 2, 2003
1,111
US
If you sub-class the VFP textbox and use it on your forms (something I recommend doing) then this is a quick way to incorporate a different color background on your text fields for the required fields.

When a user views the form, they can easily determine which fields are mandatory.

faq184-5011 Give required fields a different background color

Jim Osieczonek
Delta Business Group, LLC
 
Jim, can I ask your thoughts on this. . .

. . .required fields have lite red background if required and regular white or lite green when "answered". How might you do that?

(. . .I have be using a red "X" label next to the field and making visible/invisible accordingly, bit of a hassle to maintain.)

Any thoughts?

Bill
 
I played with it a bit and got it working. I don't know if it was the best way, but it seems to work well.

Here is what I did.

On the textbox (at the library level) I created a new class (method) and called it colorbackground.

I placed the following code in this new method:

Code:
IF This.Required
	* This.Backcolor = 16777215		&& White Background
 	* This.Backcolor = 8454143		&& Yellow Background
	IF EMPTY(THIS.VALUE)
 		This.Backcolor = 8421631	&& light red
	ELSE
		This.Backcolor = 8454016	&& light red
	ENDIF	 
ENDIF


In the Refresh event and valid events, of this textbox, I added the following code:

Code:
thisform.colorbackground()

Remember to add the property "required" on the textbox if you have not done so already.

Add 4 or 5 of these fields to a form. Set the required property to .t. for a few of them.

Add the following code in the VALID EVENT
DODEFAULT()

This can come before or after other valid event code.


Jim Osieczonek
Delta Business Group, LLC
 
Hi Jim.

>> Give required fields a different background color <<

You may want to add a property to your text box called RequiredBackColor and make it configurable.



Marcia G. Akins
 
Good point. I just started playing with this little class. I am going to change the faq to add sermac's request and I'll add that suggestion too.



Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top