you are right (again )the Yii ‘required’ validtor always validate a checkbox … and of course, the JS one does not. Actually, I think that Yii ‘required’ behaviour is not logical in this case. I mean if I have a checkbox and I want the user to check it, it seems quite normal to set the ‘required’ rule for this checkbox …
Anyway, here is a new version for the extension where the ‘required’ validator is simply skipped when dealing with a checkbox. The ‘compare’ + ‘compareValue’ attribute should be used instead, just as you described :
‘compareValue’ => true or 1 : I want the checkbox to be [color="#0000FF"]checked[/color]
‘compareValue’ => false or 0 : I want the checkbox to be [color="#008000"]unchecked[/color]
It is not possible to use ‘required’ + ‘requiredValue’ as this is only supported in Yii 1.1x branch, and the jformvalidate extension is not compatible with it.
Another point is that in this version, the behavior of the ‘required’ validator has been modified (that’s the all point) so, for those who are already using the extension, [color="#FF0000"]it could mean that model rule definition may have to be modified too[/color]… in particular if you’re using ‘required’ for a checkbox.
yes, your fix to activeListBox with multiple select is fine. In fact, I had done the same kind of modification for checkbox list, and it can be safely reported for multiple select list. I will report your fix in he next release, and until then, here is a new version of EJFValidate.php. Could please test it and tell me if it’s ok ?
As for your first question, I had some time to look at it and, maybe found a way to achieve what you want to (even if I must confess I don’t clearly understand why you’d like such feature ).
A solution is to not rely on the Validate JQuery plugin to do the form submit, but on a custom submitHandler, where you are in charge of submiting the form … and of course, you can do whatever you want before that : modify the form action url and add parameters.
Here is how it could look like :
$submitHandler=<<<END
function(form){
// this function will submit the form
alert('here, the form is valid, and you can do whatever you want before submiting it.');
form.action+='&my_var=my_value'; // for instance...
form.submit();
}
END;
echo EHtml::beginForm();
EHtml::setScenario("form1");
EHtml::setOptions(array(
'errorContainer'=> "div.container",
'wrapper' => 'li',
'errorLabelContainer' => "div.container ul",
'errorClass' => "invalid",
'submitHandler' => $submitHandler
));
The JS function is called once the form is valid, and it is assumed to actually submit the form. If it doesn’t do it, the JQuery plugin will not do it.
Maybe the form.action+=’&my_var=my_value’ should be more clever, but that’s just an example.
I suppose the fix is fine since I’ve have used mine successfully
I will try the remote validation as you suggest as soon as I can, but I think it’s a good solution. I bypass the problem using a single field with the all values I need using a separator in order to split and use them as single params during the request.
are you saying that it used to work with rc1 ? … I don’t think so because I have not yet implemented it (maybe that was a modification that you did ?).
I’ll try to release a new version compatible with 1.10 (including ‘requiredValue’ rule attribute) as soon as possible.
Hmm, that’s strange. I have a version 1.0.9rc1 here (containing INPUT_CHECKBOX_LIST), that works with checkbox ‘required’. But the rc1 in the forum is different. I’m confused. However, I just found out that requiredValue does not work properly with the Yii core validator, so you don’t need to hurry.
I don’t know if it’s the right time to ask for another feature? I have quite a lot of validation rules. So after entering the first input field, a user could press Enter, thus submitting the form, and at the moment he will see 20 or so error messages. I do not like that behaviour. For the core validation, I was able to limit the number of displayed errors (forum). It would be fantastic if this was possible with JSvalidation as well. My idea to accomplish this is as following: When pressing submit, we activate one validation after the other until we have 3 validations that currently fail (or we reach the end of the rules list). We do that on every submit, but do not deactivate any validation. (In order to avoid a double activation we could remember the number of the highest activated validator.) I a normal workflow (i.e. without invalidating prior entered data) that would avoid having more that 3 errors at a time. E.g.: Empty form, pressing submit, first 3 errors displayed, entering 3 fields, pressing submit, next 3 errors displayed, only entering 1 field correctly, pressing submit, 2 “old” and 1 “new” errors displayed etc. Does that sould useful?
The scenario you describe (a form with plenty of input fields) would indeed need such a feature… actually I’ve never experienced such a validation behaviour, and even if it seems intresting to me, I’m far from being a GUI & ergonomy expert … wouldn’t it be annoying for a user to get a new set of input errors to fix each time it submits the form ?
Now from a tecnical point of view the only problem I see is that this extension, as you may know, is in fact nothing but some sort of wrapper for the actual JS Query plugin that does the job. In other words, implementing the feature you describe would require heavy modifications of the underlying JS plugin … and I’m afraid I’m not as good Javascript developer as I would wish to be in order to be able to do that in an acceptable amount of time.
But I am. At least, I’m getting paid for being a usability engineer . For most cases, one would use a guided dialogue (a few input fields and a “next” button), but for that (private) project, a large form does suit well, in my eyes. I don’t think it would be annoying. Think of it from the other way round. Why are the error messages not active right from the beginning, but only when “submit” is pressed? (You implemented it that way and this was a good decision.) The same arguments would apply to question Why is it a bad decision not to display 19 error messages if the first field is filled, but the other 19 are not? (But, to be honest, that’s nothing that is tested. Common sense, experience and intuition are important skills in my profession, but the only way, to really know, is to do a usability test.)
What a pity. On 2nd thought, when pressing “submit” for the first time, you somehow activate all validations. Pobably, you do that one by one? In that case one could restrict the number of activations somehow, don’t you think? Could you point me to the code that activates the JS validations?
I don’t know about this ‘usability engineer’ thing but you sure have persuasion talent … look, this week-end I’ll dive into the JQuery plugin and see what I can do, but please note that I don’t promise anything but to do my best (as a JS beginner )
It’s been a long time that I think about re developing the JS part of the validation, so to make it 100% compatible with yii built-in validators… this way I would have better possibilities to add the kind of feature you want. Maybe I’ll do that … if only I had plenty of time
[color="#FF0000"]Version 1.0.9[/color] of the jformvalidate extension includes all fixes that were posted in this thread and also, support for the requiredValue rule parameter (‘required’ validator) which was the reason why Yii 1.0.10 was not supported … now it is !
For more details, please refer to the extension download page.
Download and have fun … any feedback is very welcome.
@mh469 : I have not found an easy way to implement the limited validation error message display on client side. This feature should also be implemented on the server side so to keep the same behaviour from the user point of view, whether client-side validation is enabled or not. Still investigating …