Home » HTML » HTML_QuickForm2 » Bug #7432
Client side validation
Details
| Request #7432 | Client side validation |
|---|---|
| Submitted | 2006-04-20 08:27 UTC |
| From | gdalle at cg06 dot fr |
| Assigned | avb |
| Status | Closed |
| Package | HTML_QuickForm2 |
| PHP Version | 4.3.10 |
| OS | Win Xp |
| Roadmaps | 0.5.0 |
Comments
[2006-04-20 08:27 UTC] gdalle at cg06 dot fr
Description:
------------
I've added a rule to an hidden element of the form. The rule calls a JavaScript function who check the validation.
When the value of the element is empty, the JS validation function isn't called.
Is there a way to force the calling of this function ?
I can modify the JavaScript generated code by updating the Callback.php file (QuickForm/Rule) but it's not "clean". Is there an another way ?
Test script:
---------------
Here is my code :
$oSelect =& $oQuickForm->addElement("hidden","ID_CATEGORIE_LIST","");
$oQuickForm->registerRule("checkCategorie","callback","checkCategorie");
$oQuickForm->addRule("ID_CATEGORIE_LIST","bla bla bla","checkCategorie",null,"client");
Here is the JavaScript generated code :
value = frm.elements['ID_CATEGORIE_LIST'].value;
if (value != '' && !checkCategorie(value) && !errFlag['ID_CATEGORIE_LIST']) {
errFlag['ID_CATEGORIE_LIST'] = true;
_qfMsg = _qfMsg + '\n bla bla bla';
}
Expected result:
----------------
The JS validation function should be executed.
Actual result:
--------------
The JavaScript validation function isn't executed because the generated code don't call the JavaScript validation function if the value of the element is empty.
[2006-04-21 11:08 UTC] gdalle at cg06 dot fr
OK, but how to check an element whatever its value?
In my exemple, the element is required sometimes according to an other element value.
Thus, I can't set this element to required with a rule like :
$oQuickForm->addRule("ID_CATEGORIE_LIST","bla bla bla","required","","client");
The JS checking function must be called all the time.
[2006-04-26 11:53 UTC] ankur at motreja dot com
Hi,
I'm facing the same problem and I agree with Gilles - if the programmer defines a custom client-side validation function, HTML QuickForm should just pass on the job of checking to it.
Changing the following line of code in HTML/QuickForm/Rule/Callback.php (near the end of the file)
return array('', "{jsVar} != '' && !{$callback}({$params})");
to the following fixes the issue
return array('', "!{$callback}({$params})");
If you'd like to see an example of the problem where one element might depend on the value of another element, please see the code at http://www.motreja.com/ankur/plain_quickform.txt
Here, textbox 1 is required only if choice 1 is selected, textbox 2 is required only if choice 2 is selected, etc.
To test, you need to select one of the choices and leave all other text fields blank.
If you haven't made the code change mentioned above, submit is successful.
Otherwise, it will bring up an alert box saying you need to fill up the correct textbox.
If the programmer defines additional rules like required for an element that has a custom validation rule, another javascript if block is generated for that.
Therefore, this change will affect only the callback rule (am I right?).
So, this change will always call the callback without additional checks.