]> wagnertech.de Git - kivitendo-erp.git/commitdiff
kivi.submit_form_with_action: fügt Hidden-»action« mit Wert zu Form hinzu & submittet
authorMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 13 Jan 2017 13:08:33 +0000 (14:08 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 13 Jan 2017 13:14:36 +0000 (14:14 +0100)
Zuerst werden alle existierenden Inputs namens »action« entfernt, damit
sich die Inputs nicht ins Gehege kommen. Anschließend wird ein neues
Hidden namens »action« mit dem übergebenen Wert erstellt, der Form
hinzugefügt, und die Form wird über $(selector).submit() sumittet.

js/kivi.js

index 6fad299b54ae1191cdd1ef301e7d923081e75d24..e05ea88f752353fa9ab30833b6cc2df39e07f9ee 100644 (file)
@@ -288,6 +288,23 @@ namespace("kivi", function(ns) {
     return true;
   };
 
+  // This function submits an existing form given by "form_selector"
+  // and sets the "action" input to "action_to_call" before submitting
+  // it. Any existing input named "action" will be removed prior to
+  // submitting.
+  ns.submit_form_with_action = function(form_selector, action_to_call) {
+    $('[name=action]').remove();
+
+    var $form   = $(form_selector);
+    var $hidden = $('<input type=hidden>');
+
+    $hidden.attr('name',  'action');
+    $hidden.attr('value', action_to_call);
+    $form.append($hidden);
+
+    $form.submit();
+  };
+
   // Return a function object by its name (a string). Works both with
   // global functions (e.g. "check_right_date_format") and those in
   // namespaces (e.g. "kivi.t8").