Jump to content
Larry Ullman's Book Forums

Activecheckbox And Client-Site Validation Problem


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 post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...