From 30688bda9d5edda7a8da833ad97bef4573b6fce9 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sat, 10 Oct 2020 19:35:10 +0200 Subject: [PATCH] Improve Input_Switch , do not echo but returns string --- include/lib/input_switch.class.php | 15 ++++++++------- include/template/param_jrn.php | 2 +- scenario/HtmlInput.test.php | 8 ++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/lib/input_switch.class.php b/include/lib/input_switch.class.php index ba67d7f55..3d8345cfe 100644 --- a/include/lib/input_switch.class.php +++ b/include/lib/input_switch.class.php @@ -45,6 +45,7 @@ class InputSwitch extends HtmlInput function input($p_name=NULL, $p_value=NULL) { + $r=""; if ($p_name!=NULL) $this->value_container=$p_name; if ($p_value!==NULL) @@ -56,25 +57,25 @@ class InputSwitch extends HtmlInput throw new Exception(_("Valeur invalide"),1); } if ($this->readOnly == TRUE) { - $this->display(); - return; + return $this->display(); } - echo HtmlInput::hidden($this->value_container, $this->value); + $r.= HtmlInput::hidden($this->value_container, $this->value); $this->javascript=sprintf('toggle_onoff(\'%s\',\'%s\');%s;',$this->icon,$this->value_container,$this->javascript); if ($this->value=='1') { - echo Icon_Action::iconon($this->icon, $this->javascript); + $r.=Icon_Action::iconon($this->icon, $this->javascript); } else { - echo Icon_Action::iconoff($this->icon, $this->javascript); + $r.=Icon_Action::iconoff($this->icon, $this->javascript); } + return $r; } function display() { if ($this->value=='1') { - echo Icon_Action::iconon($this->icon, ""); + return Icon_Action::iconon($this->icon, ""); } else { - echo Icon_Action::iconoff($this->icon, ""); + return Icon_Action::iconoff($this->icon, ""); } } diff --git a/include/template/param_jrn.php b/include/template/param_jrn.php index 6c73529d9..1d0ce32bb 100644 --- a/include/template/param_jrn.php +++ b/include/template/param_jrn.php @@ -98,7 +98,7 @@ if ( $type == 'ACH' || $type == 'VEN'||$new): javascript="toggle_row_warning_enable('negative_amount','row_warning')"; - $negative->input(); + echo $negative->input(); ?> diff --git a/scenario/HtmlInput.test.php b/scenario/HtmlInput.test.php index 027f4eb73..363a8fdc3 100644 --- a/scenario/HtmlInput.test.php +++ b/scenario/HtmlInput.test.php @@ -61,25 +61,25 @@ $http=new HttpInput();
         
     $input_switch=new InputSwitch('input_switch_value',get("input_switch_value","string","0")?>);
-    $input_switch->input();
+    echo $input_switch->input();
     
input_switch get("input_switch_value","string","0")); - $input_switch->input(); + echo $input_switch->input(); ?>

ReadOnly

     $input_switch=new InputSwitch('input_switch_readonly',0);
     $input_switch->readOnly=TRUE;
-    $input_switch->input();
+    echo  $input_switch->input();
     
input_switch readOnly=TRUE; - $input_switch->input(); + echo $input_switch->input(); ?>

Submit