<span id="RadioWidget"> <input type="radio" name="fieldName" value="1"/> <input type="radio" name="fieldName" value="2"/> <span class="radioRequiredMsg">Please make a selection.</span> </span>
The radioRequiredMsg rule is located in the SpryValidationRadio.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 example shows the CSS rules from the SpryValidationRadio.css file:
.radioRequiredMsg, .radioInvalidMsg{ display: none; } .radioRequiredState .radioRequiredMsg, .radioInvalidState .radioInvalidMsg{ 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 radioRequiredMsg 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 make a selection, however, Spry applies the appropriate class to the widget container, as follows:
<span id="RadioWidget" class="radioRequiredState"> <input type="radio" name="Radio Button1" value="1"/> <input type="radio" name="Radio Button2" value="2"/> <span class="radioRequiredMsg">Please make a selection.</span> </span>
In the preceding CSS code, the state rule with the .radioRequiredState .radioRequiredMsg contextual selector 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 |
---|---|
.radioRequiredMsg |
Causes error message to display when the widget enters the required state |
.radioInvalidMsg |
Causes error message to display when the widget enters the invalid state |