The Spry Select Validation Widget is used to validate a Select list or group of Select lists before submitting the form.
The widget structure is as follows:
<widget container> <Select list>
<message container(s)>
</widget container>
Using the provided files, the default mark up is:
<span id="spryselect1">
<select name="select1" id="select1">
<option>Option 1</option>
</select>
<span class="selectRequiredMsg">Please select an item.</span>
</span>
Widget Constructors are small pieces of javascript that activate the markup into the working widget. These scripts must come AFTER the markup on the page, since the markup needs to exist before the constructor fires.
<script type="text/javascript">
var ValidSelect1 = new Spry.Widget.ValidationSelect("spryselect1");
</script>
A basic constructor specifies the name of the widget and identifies the ID of the main markup container. The name of the widget is used to identify the widget for functions and methods.
<script type="text/javascript"> var widgetname = new Spry.Widget.ValidationSelect("id of widget container"); </script>
Constructor options allow users to specify certain attributes of the widget.
Constructor options follow the ID parameter, wrapped in curly braces {}. Options are name:value pairs, separated by a colon (:).
<script type="text/javascript">
var widgetname = new Spry.Widget.ValidationSelect("id of widget container",{option1:value, option2:value, option3:"value"});
</script>
Option | Values | Default | Description |
---|---|---|---|
isRequired | true or false | true | Determines whether any Select list need to be changed. Set to 'false' to bypass validation. |
invalidValue | a value of a Select list | null | Determines a value that will not pass validation. |
validateOn | "blur", "change" | submit | The widget always validates onSubmit. onBlur and onChange can be added with this option. Both can be applied with an array ['blur', 'change'] |
requiredClass |
any class name |
selectRequiredState | Overrides the "selectRequiredState" built-in value |
validClass |
any class name |
selectValidState | Overrides the "selectValidState" built-in value |
focusClass |
any class name |
selectFocusState | Overrides the "selectFocusState" built-in value |
invalidClass |
any class name |
selectInvalidState | Overrides the "selectInvalidState" built-in value |
<script type="text/javascript"> var ac1 = new Spry.Widget.ValidationSelect("spryselect1",{isRequired:false, validateOn:['blur','change'],invalidValue:"chooseone"}); </script>
Recall that javascript is case sensitive.
Reset the widget to its original state.
widgetName.reset();
<a href="#" onclick="spryselect1.reset(); return false;">Reset Select</a>
Validates the current state of the widget.
widgetName.validate();
<a href="#" onclick="spryselect1.validate(); return false;">Validate Select</a>
Copyright © 2008. Adobe Systems Incorporated.
All rights reserved.