[Tickets #11308] Re: Horde_Form_Type_boolean does not accept direct true or false values
bugs at horde.org
bugs at horde.org
Mon Aug 6 22:36:52 UTC 2012
DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.
Ticket URL: http://bugs.horde.org/ticket/11308
------------------------------------------------------------------------------
Ticket | 11308
Updated By | lfbm.andamentos at gmail.com
Summary | Horde_Form_Type_boolean does not accept direct true or
| false values
Queue | Horde Framework Packages
Version | Git master
Type | Enhancement
State | Feedback
Priority | 1. Low
Milestone |
Patch | 1
Owners |
------------------------------------------------------------------------------
lfbm.andamentos at gmail.com (2012-08-06 22:36) wrote:
> unless you explicitly set the value to true/false, i.e. you don't
> get the value from a submitted form.
Yes, that´s exactly the hypothesis I have in mind. Suppose you have a
hidden boolean form type that is set explicitly based on some
condition and you want this variable to survive a reload action.
Unless you explicitly set it as "on", it won´t work when, at last, you
process the result from getInfo. The trouble here is that it´s
unintuitive to explicitly set a form variable of the boolean type as
"on" instead of true or false.
For example, see the code below. Probably not the best code (maybe
should be separated in more subclasses, but it´s still a mockup), but
this is why I came upon this matter:
class Cashier_Form_Transaction extends Horde_Form
{
public function __construct($vars, $title)
{
parent::__construct($vars, $title);
$this->addHidden('', 'actionID', 'text', false, false, null);
$this->addHidden('', 'transaction_is_credit', 'boolean',
false, false, null);
$this->addHidden('', 'transaction_is_income', 'boolean',
false, false, null);
switch ($vars->get('actionID')) {
case 'money_in':
/* This variable will be translated to (bool)true in
the end. */
$this->_vars->transaction_is_income = 'on';
$trans_types = array(
'invoice' => _('Invoice'),
'deposit' => _('Deposit')
);
if (!isset($this->_vars->trans_type)){
$this->_vars->trans_type = 'invoice';
}
break;
case 'money_out':
$this->_vars->transaction_is_income = 'off';
$trans_types = array(
'bill' => _('Bill'),
'payment' => _('Payment')
);
if (!isset($this->_vars->trans_type)){
$this->_vars->trans_type = 'bill';
}
break;
}
$trans_type_enum = $this->addVariable(_('Type'),
'trans_type', 'enum', true, false, null, array($trans_types, true));
$trans_type_enum->setAction(Horde_Form_Action::factory('reload'));
switch ($this->_vars->trans_type) {
case 'invoice':
$tdhn = _('Dua date');
$this->_vars->transaction_is_credit = 'off';
break;
case 'payment':
$tdhn = _('Date');
$this->_vars->transaction_is_credit = 'off';
break;
case 'deposit':
$tdhn = _('Date');
$this->_vars->transaction_is_credit = 'on';
break;
case 'bill':
$tdhn = _('Dua date');
$this->_vars->transaction_is_credit = 'on';
break;
}
$this->addVariable(_('Account'), 'transaction_owner', 'enum',
true, false, null, array(Cashier::listAccounts(false,
Horde_Perms::EDIT, true),
true))->setDefault(Cashier::getDefaultAccount());
$clients = Cashier::listClients();
foreach ($clients as $id => $name) {
$client_enum[$id] = $name;
}
$this->addVariable(_('Client'), 'client_id', 'enum', true,
false, null, array($client_enum, true));
$this->addVariable(_('Value'), 'transaction_value', 'int',
true, false, null);
$this->addVariable(_($tdhn), 'transaction_date',
'monthdayyear', true, false, null, array())->setDefault(date('Y-m-d'));
$this->addVariable(_('Description'), 'transaction_desc',
'text', false, false, null, array(null, 60, 60));
if ($this->_vars->trans_type == 'invoice' ||
$this->_vars->trans_type == 'bill') {
$this->addVariable(_('Is it paid?'), 'is_paid',
'boolean', false, false, null);
$this->addVariable(_('Date paid'), 'date_paid',
'monthdayyear', false, false, null, array());
} else {
$this->addHidden('', 'is_paid', 'boolean', false, false, null);
}
$this->setButtons(array(_('Save'), _('Cancel')));
}
}
I´m explicitly setting some hidden boolean variables to "on" or "off",
as a way of making it work as expected, since only the string 'on'
will evaluate to true when I call the getInfo method later. But I
think it would be more intuitive if one could set this kind of
variable to true or false, hence my suggestion.
More information about the bugs
mailing list