3
* Horde_Form_Action_conditional_setvalue is a Horde_Form_Action that
4
* sets the value of one Horde_Form variable based on the value of the
5
* variable the action is attached to.
7
* $Horde: framework/Form/Form/Action/conditional_setvalue.php,v 1.19.10.1 2005/01/03 12:19:00 jan Exp $
9
* Copyright 2002-2005 Chuck Hagenbuch <chuck@horde.org>
11
* See the enclosed file COPYING for license information (LGPL). If you
12
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
14
* @author Chuck Hagenbuch <chuck@horde.org>
15
* @version $Revision: 1.19.10.1 $
18
class Horde_Form_Action_conditional_setvalue extends Horde_Form_Action {
21
* Which JS events should trigger this action?
22
* @var array $_trigger
24
var $_trigger = array('onchange', 'onload');
26
function getActionScript($form, $renderer, $varname)
28
return 'map(\'' . $renderer->_genID($varname, false) . "', '" . $renderer->_genID($this->getTarget(), false) . '\');';
31
function setValues(&$vars, $sourceVal, $arrayVal = false)
33
$map = $this->_params['map'];
34
$target = $this->getTarget();
38
if (is_array($sourceVal)) {
39
foreach ($sourceVal as $val) {
40
if (!empty($map[$val])) {
41
$vars->set($target, $map[$val], $i);
47
if (!empty($map[$sourceVal])) {
48
$vars->set($target, $map[$sourceVal]);
53
function printJavaScript()
55
$this->_printJavaScriptStart();
56
$map = $this->_params['map'];
59
var _map = new Array(<?php
61
foreach ($map as $val) {
65
echo '"' . $val . '"';
69
function map(sourceId, targetId)
72
var source = document.getElementById(sourceId);
73
var element = document.getElementById(targetId);
75
if (_map[source.selectedIndex]) {
76
newval = _map[source.selectedIndex];
81
for (i = 0; i < _map.length; i++) {
82
if (element.value == _map[i]) {
90
element.value = newval;
94
$this->_printJavaScriptEnd();