Spry

Insert the Validation Text Field widget

  1. Locate the SpryValidationTextField.js file and add it to your web site. You can find the SpryValidationTextField.js file in the widgets/textfieldvalidation directory, located in the Spry directory that you downloaded from Adobe Labs. For more information, see Prepare your files.

    For example, create a folder called SpryAssets in the root folder of your web site, and move the SpryValidationTextField.js file to it. The SpryValidationTextField.js file contains all of the information necessary for making the Text Field widget interactive.

  2. Locate the SpryValidationTextField.css file and add it to your web site. You might choose to add it to the main directory, a SpryAssets directory, or to a CSS directory if you have one.
  3. Open the web page to add the Text Field widget to and link the SpryValidationTextField.js file to the page by inserting the following script tag in the page’s head tag:
    <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> 

    Make sure that the file path to the SpryValidationTextField.js file is correct. This path varies depending on where you’ve placed the file in your web site.

  4. Link the SpryValidationTextField.css file to your web page by inserting the following link tag in the page’s head tag:
    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> 

    Make sure that the file path to the SpryValidationTextField.css file is correct. This path varies depending on where you’ve placed the file in your web site.

  5. Add a text field the page and give it a name and a unique ID:
    <input type="text" name="mytextfield" id="mytextfield"/>
  6. To add a container around the text field, insert span tags around the input tags, and assign a unique ID to the widget, as follows:
    <span id="sprytextfield1">
    	<input type="text" name="mytextfield" id="mytextfield"/>
    </span> 
  7. Initialize the text field object by inserting the following script block after the HTML code for the widget:
    <script type="text/javascript">
    	var tf1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    </script> 

    The new JavaScript operator initializes the Text Field widget object, and transforms the span tag content with the ID of sprytextfield1 from static HTML code into an interactive text field object. The Spry.Widget.ValidationTextField method is a constructor in the Spry framework that creates text field objects. The information necessary to initialize the object is contained in the SpryValidationTextField.js JavaScript library that you linked to at the beginning of this procedure.

    Make sure that the ID of the text field’s container span tag matches the ID parameter you specified in the Spry.Widgets.ValidationTextField method. Make sure that the JavaScript call comes after the HTML code for the widget.

  8. Save the page.

    The complete code looks as follows:

    <head> 
    ... 
    <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> 
    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> 
    </head>
    <body>
    	<span id="sprytextfield1">
    		<input type="text" name="mytextfield" id="mytextfield" />
    	</span>
    <script type="text/javascript">
    	var tf1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    </script>
    </body>