From 094084cb9a5b8b443d642d94989f820c265016c6 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 13 Jan 2017 14:08:33 +0100 Subject: [PATCH] =?utf8?q?kivi.submit=5Fform=5Fwith=5Faction:=20f=C3=BCgt?= =?utf8?q?=20Hidden-=C2=BBaction=C2=AB=20mit=20Wert=20zu=20Form=20hinzu=20?= =?utf8?q?&=20submittet?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/js/kivi.js b/js/kivi.js index 6fad299b5..e05ea88f7 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -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 = $(''); + + $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"). -- 2.20.1