From: Kim Alvefur Date: Tue, 24 Aug 2010 06:50:09 +0000 (+0200) Subject: Add function to serialize forms X-Git-Url: https://cgit.babelmonkeys.de/?a=commitdiff_plain;h=34a06d17adfddf8cae1671b3a1c666da238fbd61;p=adhocweb.git Add function to serialize forms --- diff --git a/js/main.js b/js/main.js index c20969d..db4a075 100644 --- a/js/main.js +++ b/js/main.js @@ -102,6 +102,7 @@ function addForm(elem, x) { default: item = $(""); } + item.addClass("df-item"); if ($(this).find("value")) { var value = null; if ((type == "text-multi") || (type == "jid-multi")) { @@ -129,6 +130,27 @@ function addForm(elem, x) { $(elem).append(form); } +function serializeToDataform(form, st) { + st.c("x", {"xmlns":"jabber:x:data", "type": "submit"}); + $(form).find(".df-item").each(function(){ + st.c("field", {"var": $(this).attr("name")}); + if(this.nodeName.toLowerCase() == "select" && this.multiple) { + for(var i = 0; i < this.options.length; i++) + if(options[i].selected) + st.c("value").text(options[i]).up(); + } else if(this.nodeName.toLowerCase() == "textarea") { + var sp_value = this.value.split(/\r\n?|\r/g); + for(var i = 0; i < sp_value.length; i++) + st.c("value").text(sp_value[i]).up(); + } else { + // if this has value then + st.c("value").text($(this).val()).up(); + } + st.up(); + }); + st.up(); +} + function displayResult(result) { var status = $(result).find("command").attr("status");