Re: QuickForm::addRule in groups

From: Date: Tue, 08 Apr 2003 13:44:29 +0000
Subject: Re: QuickForm::addRule in groups
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-15026@lists.php.net to get a copy of this message
<wolfram@visionp.de> wrote : > if i add a rule for an element in a group, the _required is not passed > on to the group, am i right? therefore the renderer doesnt see that > the element (in the group) is required > I am using the latest CVS version (which becomes v3, I guess) I am posting a small example to show how rules work. First, you create the group: $group[0] =& HTML_QuickForm::createElement('html','info text'); $group[1] =& HTML_QuickForm::createElement('textarea','input','input'); $form->addGroup($group, 'mygroup', 'Group Label:'); (pay attention to the & in front of HTML_QuickForm::createElement) (don't forget to add your group to the form with addGroup and give it a name). Then, you can choose the way your group is required: 1. have only one element in the group required and you specify which one $rule[0][0] = array('This is required', 'required'); $form->addGroupRule('mygroup', $rule); We took 0 as an index because it's the name you gave to the element index in $group array. It could have been an associative array too for better readability. 2. have two elements required by specifying which ones $rule[0][0] = array('This is required', 'required'); $rule[1][0] = array('This is required', 'required'); $form->addGroupRule('mygroup', $rule) 3. have at least one of the elements required without specifying which one $form->addGroupRule('mygroup', 'At least one is required', 'required', null, 1); 4. have the whole group required as if it were an element $form->addGroupRule('mygroup', 'All fields are required', 'required'); When you deal with a group, it's recommended to use addGroupRule() because it offers more options. Good luck, Bertrand Mansion Mamasam > i.e. this > > $group[0] = HTML_QuickForm::createElement('html','info text'); > $group[1] = > HTML_QuickForm::createElement('textarea','input','input'); > $form->addRule($group[1]->getName(),'This is required!','required'); > > and in the Renderer (i use an customized version of the > Default-Renderer) renderElement() doesnt get the paramter > $required=true passed to it. > > I think the bug is in QuickForm::addRule() > > if ($type == 'required' || $type == 'uploadedfile') { > $this->_required[] = $element; > } > should be > if ($type == 'required' || $type == 'uploadedfile') { > if ($this->isInGroup($element)) { > $groupName = $this->getGroup($element); > $this->_group[$groupName]->setRequired($element); > } else { > $this->_required[] = $element; > } > } > > > i am not an QuickForm-Expert. And i dont know if there are methods such as > isInGroup() > getGroup() > etc. > > What do you say? >

« previous php.pear.dev (#15026) next »