Help with HTML_QuickForm2
| From: | RIch Payne | Date: | Tue, 06 Mar 2012 21:26:12 +0000 |
| Subject: | Help with HTML_QuickForm2 | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-31444@lists.php.net to get a copy of this message | ||
Hello,
First of all I'd like to say thanks to those who've developed QF2, I've
found it a useful piece of code. I'm having an issue that I hope someone
can help with. I'm using QF2 to generate a form and one of the 'features'
I'd like to have in the form is help text for the users filling it out. So
basically each row in the form would be:
Question? (icon for help): <html input element>
Now, the (icon for help) is just basically a question mark icon that the
user can click on. This pops up a modal window using jquery to give them
some help text. Now I have all this working, except, if the user navigates
through the form using the keyboard (tab keys) I get a javascript error
when the focus goes from the icon to the next html input field. The error
is:
"form is undefined"
Which comes from this piece of javascript (generated by the QF2 client side
validation code I believe)
qf.Validator.liveHandler = function (event)
{
event = qf.events.fixEvent(event);
var form = event.target.form;
if (form.validator) { <<<<<<<
form.validator.runLive(event);
}
};
So it seems it's trying to validate an item which isn't really part of the
form? If the icon never gets focus (user goes through and clicks the mouse
on each field), no errors of course. Here's a snippet of php to generate
the error:
<?php
require_once 'HTML/QuickForm2.php';
require_once 'HTML/QuickForm2/Renderer.php';
$form = new HTML_QuickForm2('testForm');
$fsTest = $form->addElement('fieldset')->setLabel('Test Area:');
$fsElement1=$fsTest->addElement('text','testBox1')
->setLabel('Question:<a href="somefile.php"
class="modal"><img
src=question.png alt="Help" width=24 height=24></a>');
$fsTest->addElement('submit', 'testSubmit', array('value' =>
'Submit'));
$fsElement1->addRule('required','Required Field',null,
HTML_QuickForm2_Rule::ONBLUR_CLIENT_SERVER);
$renderer = HTML_QuickForm2_Renderer::factory('default');
$form->render($renderer);
echo $renderer->getJavascriptBuilder()->getLibraries(true, true);
echo $renderer;
?>
I've tried using a 'Static' element instead of embedding it in the Label,
same behaviour. The only work around I've though of would be to not use an
<a> and instead use a onclick from the icon.....but wanted to see if I had
other options first.
Thoughts?
thx,
--rdp