What is correct way of using $htmlOptions[‘clientValidation’] attribute for CActiveForm.error() function?
Citing documentation:
[size=2]OK. So I’m using a code like this:[/size]
<?php
$validationArray = array
(
'hideErrorMessage'=>TRUE,
'clientValidation'=>'js:afterValidateAttribute'
);
?>
<div class="row">
<?php echo($form->labelEx($model, 'name')); ?>
<?php echo($form->textField($model, 'name')); ?>
<?php echo($form->error($model, 'name', $validationArray)); ?>
</div>
[size=2]And a very strange things happens.[/size]
Not only, my Javascript function [size="2"]afterValidateAttribute() is not being called / executed, but also, when I take a look into source code, I see some garbage.[/size]
[size="2"]Error fields looks like this:[/size]
[size="2"]
<div clientValidation="js:afterValidateAttribute" class="errorMessage" id="Contact_subject_em_" style="display:none"></div>
[/size]
[size="2"]so Yii is rendering [/size][size="2"]clientValidation as a normal attribute. Also it does not stop serving default (built-in) client-side validator (it should supply my own, if I understand these things correctly), but in adds a strange string inside. So particular client-side validator looks like this:[/size]
[size="2"]
'clientValidation':function(value, messages, attribute)
{
js:afterValidateAttribute
if($.trim(value)=='')
{
messages.push("Field can't be empty!");
}
if($.trim(value)!='')
{
if(value.length>70)
{
messages.push("Field's content is too long");
}
}
}
[/size][size="2"]Is this some kind of bug?[/size]
[size=“2”]If I’m not missing something obvious or doing something very wrong, [/size][size=“2”]using[/size] $htmlOptions[‘clientValidation’] [size=“2”]attribute is completely useless for me. I managed to apply my own, custom client-side validation only by turning build-in client validation off ([/size]hideErrorMessage) and using afterValidateAttribute. I failed completely doing this easier way, i.e. using clientValidation[size=“2”].[/size]