Login Retreive lost passwordRegister
Search

Forum Index / Feedback / Request: vertically stacked listfield

[ This topic is solved ]

  Rick den Haan 12 March 08 / 13:59  
Could an extra argument be added to the listField()-function to indicate whether the two selectfields should be stacked horizontally or vertically?

Currently, the fields are always side-by-side, with the left/right buttons in between. This breaks layouts quite quickly when you have little to no control over the options. In a recent project there were options varying from 200 to almost 300 pixels wide in both columns.

Having the ability to stack the two selectfields vertically, with up and down buttons, would have saved my layout (I now just used a selectField with the multiple-flag set to true).

  Teye Heimans (Founder) 12 March 08 / 14:02  
It is possible to change the mask of the listfield in the config file. Maybe that is the best (quick) solution for you. Good luck

  Rick den Haan 13 March 08 / 17:25  
True, but what if I want the listfield vertically stacked in one form, and horizontally on another form in the same website?

  Teye Heimans (Founder) 13 March 08 / 17:44  
Changed at 13 March 08 / 17:45
You can override the default value: check this page...

So you can set your custom listfield mask above one form, and use the default in the rest of your forms.

However, it is not possible to have both types (vertical and horizontal) in one form.

  Rick den Haan 14 March 08 / 13:52  
I modified FH myself to do this ;-)

It did take a bit of work, but not as much as I'd feared.

In FH3/includes/config.inc.php:
<?php
// The mask used for the listfield
fh_conf('FH_LISTFIELD_MASK',
  
"...etc..."
);

// modified to:

// The mask used for the horizontal listfield
fh_conf('FH_LISTFIELD_HORIZONTAL_MASK',
  
"...unchanged..."
);

// The mask used for the vertical listfield (needs
// finetuning, just a proof-of-concept)
fh_conf('FH_LISTFIELD_VERTICAL_MASK',
  
"  <table border='0' cellspacing='0' cellpadding='0'>\n".
  
"    <tr>\n".
  
"      <td align='right' valign='middle'><b>%offlabel%</b></td>\n".
  
"      <td valign='top' align='left'>\n".
  
"        %offfield%\n".
  
"      </td>\n".
  
"    </tr>\n".
  
"    <tr>\n".
  
"      <td colspan='2' height='30' align='center' valign='middle'>\n".
  
"        <input type='button' value=' &darr; ' onclick=\"changeValue('%name%', true)\" ondblclick=\"moveAll('%name%', true)\" title='%offtitle%' />&nbsp;\n".
  
"        &nbsp;<input type='button' value=' &uarr; ' onclick=\"changeValue('%name%', false)\" ondblclick=\"moveAll('%name%', false)\" title='%ontitle%' />\n".
  
"      </td>\n".
  
"    </tr>\n".
  
"    <tr>\n".
  
"      <td align='right' valign='middle'><b>%onlabel%</b></td>\n".
  
"      <td valign='top' align='left'>\n".
  
"        %onfield%\n".
  
"      </td>\n".
  
"    </tr>\n".
  
"  </table>"
);
?>


In FH3/class.FormHandler.php:
<?php
    
function listField(
      
$title,
      
$name,
      
$options,
      
$validator          null,
      
$useArrayKeyAsValue null,
      
$onTitle            null,
      
$offTitle           null,
      
$size               null,
      
// Modified from here:
      
$extra              null,
      
$verticalMode       null)
    {
        
//snip...
        
if(!empty($size))                 $fld->setSize$size );
        if(!empty(
$extra))                $fld->setExtra$extra );
        if(!empty(
$onTitle))              $fld->setOnTitle$onTitle );
        if(!empty(
$offTitle))             $fld->setOffTitle$offTitle );
        
// Added this line
        
if(!empty($verticalMode))         $fld->setVerticalMode$verticalMode );
        
//...snip
    
}
?>

(Make the same modifications to the dbListField function in FH3/class.dbFormHandler.php)

In FH3/fields/class.ListField.php:
<?php
class ListField extends Field
{
    
// Added this line at the top
    
var $_bVerticalMode;
    
    
// Added this function
    
function setVerticalMode($bVerticalMode)
    {
        
$this->_bVerticalMode $bVerticalMode;
    }

    function 
getField()
    {
        
// Find these lines (at the bottom):
        
str_replace(
          array(
            
'%onlabel%',
            
'%offlabel%',
            
'%onfield%',
            
'%offfield%',
            
'%name%',
            
'%ontitle%',
            
'%offtitle%'
          
),
          array(
            
$this->_sOnTitle,
            
$this->_sOffTitle,
            
$this->_oOn->getField(),
            
$this->_oOff->getField(),
            
$this->_sName,
            
sprintf$this->_oForm->_text34 ), htmlentitiesstrip_tags($this->_sOffTitle)) ),
            
sprintf$this->_oForm->_text34 ), htmlentitiesstrip_tags($this->_sOnTitle)) )
          ),
          
FH_LISTFIELD_MASK
        
) .
        (isset(
$this->_sExtraAfter) ? $this->_sExtraAfter :'');

        
// Replace with:
        
str_replace(
          array(
            
'%onlabel%',
            
'%offlabel%',
            
'%onfield%',
            
'%offfield%',
            
'%name%',
            
'%ontitle%',
            
'%offtitle%'
          
),
          array(
            
$this->_sOnTitle,
            
$this->_sOffTitle,
            
$this->_oOn->getField(),
            
$this->_oOff->getField(),
            
$this->_sName,
            
sprintf$this->_oForm->_text34 ), htmlentitiesstrip_tags($this->_sOffTitle)) ),
            
sprintf$this->_oForm->_text34 ), htmlentitiesstrip_tags($this->_sOnTitle)) )
          ),
          (!empty(
$this->_bVerticalMode) && $this->_bVerticalMode) ? FH_LISTFIELD_VERTICAL_MASK FH_LISTFIELD_HORIZONTAL_MASK
        
) .
        (isset(
$this->_sExtraAfter) ? $this->_sExtraAfter :'');
    }
}
?>


I added the $verticalMode argument as the last one in the listField() and dbListField() function call, so as not to break other forms that use the $extra argument. I can now do this to display a vertically stacked listField:
<?php
    $oForm
->listField("Test""test", array('a','b','c','d','e','f','g','h'), nullnullnullnullnullnulltrue);
?>

For the regular (horizontal) listField I can leave off the last argument, or set it to null or false.

  Johan Wiegel (Admin) 20 March 08 / 10:23  
Rick,

as you did the work and we think it is a good addition we will put this in the next version.

Johan

  Rick den Haan 27 March 08 / 10:26  
You did test it though, right?

I've only used this mod in one site under very specific circumstances, so it might not work everywhere. And the mask may look terrible ;-)

  Johan Wiegel (Admin) 27 March 08 / 10:42  
I did some testing ;) and it seems to work well.

The mask is just the default mask, it's good enough.

Thanks for the great work.

  Top


powered by PHP-GLOBE   © 2004 - 2008 FormHandler. All rights reserved.   -   Open source license