calculate_qty (Formel): Input- und Formel-Feld auch als Dom-Id übergeben können
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 9 May 2018 12:21:45 +0000 (14:21 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 14 May 2018 11:23:05 +0000 (13:23 +0200)
bin/mozilla/io.pl
js/calculate_qty.js
templates/webpages/generic/calculate_qty.html

index 7cdc751..fa63004 100644 (file)
@@ -319,7 +319,7 @@ sub display_row {
     my $qty_dec = ($form->{"qty_$i"} =~ /\.(\d+)/) ? length $1 : 2;
 
     $column_data{qty}  = $cgi->textfield(-name => "qty_$i", -size => 5, -class => "numeric", -value => $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec));
-    $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i', 'formel_$i')", -value => $locale->text('*/'))
+    $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i', '', 'formel_$i')", -value => $locale->text('*/'))
                        . $cgi->hidden(-name => "formel_$i", -value => $form->{"formel_$i"})
       if $form->{"formel_$i"};
 
index e0aecc4..01fa5bf 100644 (file)
@@ -1,11 +1,17 @@
-function calculate_qty_selection_window(input_name, formel) {
+function calculate_qty_selection_window(input_name, input_id, formel_name, formel_id) {
   var parm = centerParms(600,500) + ",width=600,height=500,status=yes,scrollbars=yes";
   var action = "calculate_qty";
+  if (formel_id) {
+    var formel = $('#' + formel_id).val();
+  } else {
+    var formel = $('[name="' + formel_name + '"]').val();
+  }
   url = "common.pl?" +
     "INPUT_ENCODING=UTF-8&" +
     "action=" + action + "&" +
     "input_name=" + encodeURIComponent(input_name) + "&" +
-   "formel=" + encodeURIComponent(document.getElementsByName(formel)[0].value)
+    "input_id="   + encodeURIComponent(input_id)   + "&" +
+    "formel=" + encodeURIComponent(formel);
   //alert(url);
   window.open(url, "_new_generic", parm);
 }
index 49c1054..3d2910c 100644 (file)
@@ -5,6 +5,7 @@
  <form name="Form">
 
   <input type="hidden" name="input_name" value="[% HTML.escape(input_name) %]">
+  <input type="hidden" name="input_id"   value="[% HTML.escape(input_id) %]">
 
   <table width="100%">
    <tr><td>[% 'Please insert object dimensions below.' | $T8 %]</td></tr>
 [%- END %]
      var result = [% formel %];
      result = number_format(result, 2, '[% MYCONFIG.numberformat %]');
-     window.opener.document.getElementsByName(document.Form.input_name.value)[0].value = result;
+     if (document.Form.input_id.value) {
+       window.opener.document.getElementById(document.Form.input_id.value).value = result;
+     } else {
+       window.opener.document.getElementsByName(document.Form.input_name.value)[0].value = result;
+     }
      self.close();
    }