logo       

Re: QFC - Register Rule: msg#00354

php.pear.general

Subject: Re: QFC - Register Rule

Another approach would be to create the 'explanation" text box regardless,
but mask it with a bit of javascript. Typically your renderer will render
the explanation textbox as a separate row. So you want to mask the row
depending on the value of the current radio value.

Define your custom renderer so that it generate row id attributes to all
rows in your and a table id as well.
Then add a Javascript that executes after loading the form table:

<script language='JavaScript'>
//<![CDATA[

var table1 = document.getElementById( "table1" ) ;
var show = ( form1.myradioelement.value != "other" ? "none" : "block" ) ;
table1.rows[ <id for the 'explanation' tetx box>].style.display = show ;

Caution (I learned this the hard way): in your document "name" and "id"
attributes share the same namespace, so they must be unique. Be careful then
when generating the row ids.

HTH
Ignatius
_________________________
"Barry Steele" <barry@xxxxxxxx> wrote in message
news:1069296364.11433.40.camel@xxxxxxxxx
> Hi,
> I'm doing something wrong here, I've just moved a multipage form into
> the QFC framework. I have a number of genericaly useful function for
> generating checkbox groups, radio buttons which like a good C programmer
> I put into a "misc.php" -
>
> a number of the checkboxes are for questions such as "choose
> a,b,c,d,other ) if other then it produces a text box for 'Explanation'.
> I have a validation function that checks for the "other" option and
> fails if there is a null value in the text box.
>
> // Start of sample code
>
> function getCheckBoxExplanationRule($elements,$explFlags)
> /*
> --------------------------------------------------------------------
> getExplanation
> Function will test an array of elements to ensure that if an
> option
> requies an explanation (from the the Database) it has been
> entered. The
> logic for this is simply if an option is followed by a
> textbox/explanation
> field and is checked then if that text box is not entered the
> function
> returns false.
>
> --------------------------------------------------------------------
> */
> {
> foreach ($elements as $k=>$v)
> {
> $flag = $explFlags[$k];
> if ($explFlags[$k] == 'Y')
> {
> if (!isset($elements['explFlag']) || ($elements['explFlag']
> ==""))
> {
> return false;
> }
> }
> }
> return true;
> }
>
>
> function getRadioExplanationRule($elements,$explFlags)
> {
> foreach ($elements as $k=>$v)
> {
> if ($explFlags[$v] == 'Y')
> {
> if ((!isset($elements['explFlag'])) ||
> ($elements['explFlag'] == ""))
> {
> return false;
> }
> }
> }
> return true;
> }
>
> // End of code
> I regisiter the function as follows in the original
>
>
> // more code <code>
>
$this->inputForm->registerRule('checkBoxExpl','function','getCheckBoxExplana
tionRule','incidentReportForm');
>
>
$this->inputForm->registerRule('checkRadioExpl','function','getRadioExplanat
ionRule','incidentReportForm');
>
> $this->inputForm->addRule('incLocation','Please add explanation
> as
>
required','checkRadioExpl',$this->getExplFlds($this->getReferences($db,'Loca
tion')));
>
> // end of code </code>
>
>
>
> Now I want to call it from a page in qfc, I used the following
>
> // <code>
> require_once "misc.php";
>
> class IncidentPage extends HTML_QuickForm_Page
> {
> function buildForm()
> {
> // blah - build fields
>
>
$this->registerRule('checkBoxExpl','function','getCheckBoxExplanationRule');
>
>
$this->registerRule('checkRadioExpl','function','getRadioExplanationRule');
> }
> }
> // </code>
>
> This is wrong because it never gets called - should I include all of
> these functions in a parent form and sub-class that into QFC?
>
> Or is it even easier?
>
> THanks for the great work on QFC, it is sinpirational. I look forward
> to working with you as I get this more under control, and hopefully will
> need services to build things over the next few years.
>
>
> hpfm
> Barry Steele
> hpfm solutions pty ltd
> mob: 0413947980
> fax: 0299817727
> mailto:: barry@xxxxxxxx

--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise