View comments | RSS feed

Spry

Display error messages

 Create a span tag (or any other type of tag) to display the error message, and assign the appropriate class to it, as follows:
<span id="sprytextfield1">
	<input type="text" name="mytextfield" id="mytextfield" />
	<span class="textfieldRequiredMsg">Please enter a description</span>
</span>

The textfieldRequiredMsg rule is located in the SpryValidationTextField.css file, and is set to display:none by default. When the widget enters a different state through user interaction, Spry applies the appropriate class—the state class—to the container of the widget. This action affects the error message class, and by extension, the appearance of the error message.

For example, the following shows a portion of the CSS rule from the SpryValidationTextField.css file:

.textfieldRequiredMsg,
.textfieldInvalidFormatMsg,
.textfieldMinValueMsg,
.textfieldMaxValueMsg,
.textfieldMinCharsMsg,
.textfieldMaxCharsMsg,
.textfieldValidMsg {
	display: none;
}
.textfieldRequiredState .textfieldRequiredMsg,
.textfieldInvalidFormatState .textfieldInvalidFormatMsg,
.textfieldMinValueState .textfieldMinValueMsg,
.textfieldMaxValueState .textfieldMaxValueMsg,
.textfieldMinCharsState .textfieldMinCharsMsg,
.textfieldMaxCharsState .textfieldMaxCharsMsg{
	display: inline;
	color: #CC3333;
	border: 1px solid #CC3333;
}

By default, no state class is applied to the widget container, so that when the page loads in a browser, the error message text in the preceding HTML code example only has the textfieldRequiredMsg class applied to it. (The property and value pair for this rule is display:none, so the message remains hidden.) If the user fails to enter text in a required text field, however, Spry applies the appropriate class to the widget container, as follows:

<span id="sprytextfield1" class="textfieldRequiredState">
	<input type="text" name="mytextfield" id="mytextfield" />
	<span class="textfieldRequiredMsg">Please enter a description</span>
</span>

In the preceding CSS code, the state rule with the contextual selector .textfieldRequiredState .textfieldRequiredMsg overrides the default error-message rule responsible for hiding the error-message text. Thus, when Spry applies the state class to the widget container, the state rule determines the appearance of the widget, and displays the error message inline in red with a 1-pixel solid border.

Following is a list of default error-message classes and their descriptions. You can change these classes and rename them. If you do so, don’t forget to change them in the contextual selector also.

Error message class

Description

.textfieldRequiredMsg

Causes error message to display when the widget enters the required state

.textfieldInvalidFormatMsg

Causes error message to display when the widget enters the invalid state

.textfieldMinValueMsg

Causes error message to display when the widget enters the minimum value state

.textfieldMaxValueMsg

Causes error message to display when the widget enters the maximum value state

.textfieldMinCharsMsg

Causes error message to display when the widget enters the minimum number of characters state

.textfieldMaxCharsMsg

Causes error message to display when the widget enters the maximum number of characters state

.textfieldValidMsg

Causes error message to display when the widget enters the valid state

Note: You cannot rename state-related class names because they are hard-coded as part of the Spry framework.

Comments

Comments are no longer accepted for Spry 1.4. Spry 1.6 is the current version. To discuss Spry 1.4, please use the Adobe forum.

Comments


No screen name said on Jul 24, 2008 at 12:47 PM :
The .textfieldValidMsg property does not work. 3 guys have tried it all on separate computers using Dreamweaver CS3. The display: none property seems to be in effect no matter what. Has this been fixed - is there a patch - or what?
jambajuiced said on Nov 13, 2008 at 9:25 AM :
You can fix this by adding the following style to SpryValidationTextField.css

.textfieldValidState .textfieldValidMsg {display: inline;}

That will override the display:none style that is applied by default, once the Spry javascript changes the state to .textfieldValidState.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/en_US/Spry/1.4/WSFE3BE966-7A7C-411d-A941-8AFE1AA9ED35.html