Jump to content
Larry Ullman's Book Forums

Activecheckbox And Client-Site Validation Problem


Ziggi
 Share

Recommended Posts

Hmm,

 

This looks like a bug actually but you may be more clever than myself:

 

presuming we have a form:

 

<div class="form">

<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'users-form',
'enableClientValidation'=>true,
'clientOptions' => array(
 'validateonsubmit'=>true,
 'validateonchange'=>true,
 'validateOnType'=>false,
),
));
?>

<div class="row">
 <?php echo $form->labelEx($model, 'active'); ?>
 <?php echo $form->checkBox($model, 'active', array('uncheckValue'=>0)); ?>
 <?php echo $form->error($model,'active'); ?>
</div>

 

Having client-side validation enabled this way it is imposible to uncheck the 'active' checkbox in case:

 

array('active', 'required', 'message'=>'{attribute} cannot be null !')

 

in a model validation rules.

 

This looks like a discrepancy as the class documentation reads clear:

 

A special option named 'uncheckValue' is available that can be used to specify the value returned when the checkbox is not checked. By default, this value is '0'. Internally, a hidden field is rendered so that when the checkbox is not checked, we can still obtain the posted uncheck value. If 'uncheckValue' is set as NULL, the hidden field will not be rendered.

 

And this is working actually in case a form is submitted having client validation switched off. But it seems client validation javascript is unaware of this documentation!

Link to comment
Share on other sites

  • 2 weeks later...
 Share

×
×
  • Create New...