From 34a06d17adfddf8cae1671b3a1c666da238fbd61 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 24 Aug 2010 08:50:09 +0200 Subject: [PATCH] Add function to serialize forms --- js/main.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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"); -- 2.39.5