Hi Guys and Gals,
I’ve just noticed that all of the Zii widgets I have used on my tabular input forms (CJuiAutoComplete, CJuiDatePicker) aren’t getting the error class applied to them when the form is validated.
See the picture below of a datepicker field that has an invalid date but the input isn’t highlighted like the one above it.
2435
The code for the widget within the form is as follows. It’s used in a tabular input form hence the [$i] in the attributes.
<tr>
<td class="label-cell-1"><?php echo $form->labelEx($model, "[$i]email_address"); ?></td>
<td class="input-cell-1"><?php echo $form->textField($model, "[$i]email_address", array('size'=>50, 'maxlength'=>100)); ?>
<?php echo $form->error($model, "[$i]email_address"); ?></td>
</tr>
<tr>
<td class="label-cell-1"><?php echo $form->labelEx($model, "[$i]date_of_birth"); ?></td>
<td class="input-cell-1"><?php
$form->widget('zii.widgets.jui.CJuiDatePicker', array(
'themeUrl'=>Yii::app()->theme->baseUrl.'/jquery/jui/css',
'model'=>$model,
'attribute'=>"[$i]date_of_birth",
'options'=>array(
'defaultDate'=>'-30y',
),
));
?>
<?php echo $form->error($model, "[$i]date_of_birth"); ?></td>
</tr>
Now here’s the strange thing - if I take out the [$i] bit of the attribute, the validation highlighting works (but the data never saves because there’s no tabular index number). Also, all of the forms where I don’t have tabular input are fine (e.g. registration form, contact form etc). Those other forms are using exactly the same widget code, with the exception of the attribute not having the [$i] bit.
Now, I’m not sure if this validation highlighting has ever worked on my site with tabular input (I don’t remember checking it when I was first implementing the widgets).
FYI I am using the following versions:
-
Yii 1.1.9
-
jQuery UI 1.8.16 (bundled with Yii 1.1.9)
Also, here’s the generated HTML code from an unvalidated form…
<tr>
<td class="label-cell-1"><label for="Member_0_email_address">Email Address</label></td>
<td class="input-cell-1"><input size="50" maxlength="100" name="Member[0][email_address]" id="Member_0_email_address" type="text" value="mike.walen@xxxxxxxx.com" /></td>
</tr>
<tr>
<td class="label-cell-1"><label for="Member_0_date_of_birth" class="required">Date Of Birth <span class="required">*</span></label></td>
<td class="input-cell-1"><input id="Member_0_date_of_birth" name="Member[0][date_of_birth]" type="text" value="1977-09-12" /></td>
</tr>
…and the generated jQuery code at the bottom of the page…
jQuery('#Member_0_date_of_birth').datepicker({'showButtonPanel':true,'changeYear':true,'dateFormat':'yy-mm-dd','yearRange':'c-70:c+30','defaultDate':'-30y'});
So I’m hoping some of you can help me out. For those of you using tabular forms with widgets, could I pretty-please ask you to take a quick look at your own sites and see if you’re getting the validation highlighting on your Zii widgets?
Many thanks.