Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.3.2

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 (version 3.2.5)
PHP Version: 4.3.10 OS: Win Xp
Roadmaps: 0.5.0    
Subscription  


 [2006-04-20 08:27 UTC] gdalle at cg06 dot fr (Gilles)
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.

Comments

 [2006-04-21 10:09 UTC] avb (Alexey Borzov)
If an element is not made required and is empty, then other validation rules are not run for it. This is documented behaviour.
 [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 (Ankur Motreja)
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.
 [2006-06-03 14:40 UTC] avb (Alexey Borzov)
The current way of checking the element's value based on other elements' values is by writing a custom function and plugging it in with addFormRule(). The example file formrule.php shows this approach. Currently addFormRule() does not do anything with client side validation. I think it should be improved so that custom javascript functions working on several elements can be plugged in, too.
 [2006-06-18 20:14 UTC] avb (Alexey Borzov)
Moving the rest of feature requests to HTML_QuickForm2.
 [2006-07-20 14:28 UTC] areddan at silverarm dot ie (Alan Reddan)
Description -------------- What happens is the button onclick overrides the onSubmit and passes the validation to displayWaiting() This performs the validation routine by directly calling the quickFrom client side javascript, if this is ok then it moves onto the next step which is to display a progress bar animated gif called loading.gif using setTimeout as a form submit cocks up animation and IE. This works with IE 6.0 and Mozilla 1.5 Solution --------------------------- ########Your php script $form =& new HTML_QuickForm('bookme', 'post'); $form->addElement('checkbox', 'checked_terms', array('Terms & Conditions', ''.$click),'',array('class' =>'bkChe')); $form->addRule('checked_terms', 'You must indicate you have read our terms and conditions', 'required', null, 'client'); $submit_data_tr =<<$submit_data
</td></tr> EOF; $form->addElement('html',$submit_data_tr); $buttons[] = &HTML_QuickForm::createElement('button', '', $finish,array('class' =>'qfSub','onclick' =>'displayWaiting();')); $form->display();
 [2010-10-07 19:26 UTC] avb (Alexey Borzov)
-Status: Analyzed +Status: Closed -Assigned To: +Assigned To: avb
It is now possible to write a custom Rule subclass in QuickForm2 that would behave like addFormRule() callback in QuickForm (one has to override validateOwner() and setOwnerError() for that). Also it is possible to implement client-side validation for such a rule since 'errors' hash map in Validator is exposed to the rule callback. Oh, and callback in Callback / NotCallback rule is called even if the element's value is empty.