The below spry validation form was created with DW CS6
I created an HTML form and posted it with PHP to a MySQL database. One of the form lines is to enter a date. That line is using a "out of the box" sprytextfield data validation without modification to any of its CSS or JS:
HTML
<span id="sprytextfield1">
<label for="servComDate">Starting Date?</label>
<input type="text" name="servComDate" id="servComDate">
<span class="textfieldRequiredMsg">A value is required.</span>
<span class="textfieldInvalidFormatMsg">Invalid format.</span>
</span>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {hint:"00/00/0000", format:"mm/dd/yyyy"});
</script>
On submission, the form value is captured via PHP and the date format is converted to a MySQL format before entering it into the database.
PHP
$servComDate = date("Y-m-d", strtotime($_POST['servComDate']));
All of the above is working perfectly.
Now, I have created a different page with an HTML form to edit the information. First, the PHP pulls the field from the database and converts it from the MySQL format back to the format used in the above sprytextfield it was created in.
PHP
$servComDate = strftime("%m/%d/%Y", strtotime($row["servComDate"]));
Then the HTML form is populated with the existing value
HTML
<span id="sprytextfield1">
<label for="servComDate">If the Service is Coming Soon, do you know when the service will start being offered?</label>
<input type="text" name="servComDate" id="servComDate" value="<?php echo $servComDate; ?>">
<span class="textfieldRequiredMsg">A value is required.</span>
<span class="textfieldInvalidFormatMsg">Invalid format.</span>
</span>
When pre-populating the form with the existing value it displays with the proper format in the input box, but shows these "errors":
value is required. Invalid format.
As I said above, I have not changed any of the CSS or JS that is loaded with the Spry textfield, so I did not include that here.
I am obviously doing something wrong with pre-populating a Spry textfield with a default value.
What is the correct what to have a default value on a Spry Validation Date Textfield?
Thanks in advance!
Make sure that in the Edit page the constructor looks like
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {hint:"00/00/0000", format:"mm/dd/yyyy"});
The following works fine for me
<span id="sprytextfield1">
<label for="text1"></label>
<input type="text" name="text1" id="text1" value="<?php echo strftime("%m/%d/%Y", strtotime($row_Recordset1['UserRegistrationDate'])); ?>">
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {hint:"00/00/0000", validateOn:["blur"], format:"mm/dd/yyyy"});
</script>
Gramps
Your are going to love this...
I confirmed I have the constructor same as yours. Only difference in your code and mine is I did not have the validateOn blur in the Javascript, but rather was using the default validation on submission. However, I dutifully added that, just to replicate your test exactly and to look at apples to apples. The code is still throwing up the validation messages.
Stumped, I took a break, played a video game, cleared the mind and started the process of carefully and logically working the code for about the umpteenth time in the last 24 hours.
Given this validation is working just fine on the page where new items are created, I laid out that pages code next to the edit page code and started going through line by line... and Eureka! No reference in my edit page head to the SpryValidationTestField.js... (**red faced, banging head on desk**)
That's 2 for 2 with you helping me realize its not the Spry code, so it must be something else and that something else, once again, was me. The human error element. If I hit strike three down the road I deserve a sound verbal thrashing...
Once again I am in your debt and you have my gratitude!
Thank you Gramps!
North America
Europe, Middle East and Africa
Asia Pacific