]> git.babelmonkeys.de Git - adhocweb.git/commitdiff
Add function to serialize forms
authorKim Alvefur <zash@zash.se>
Tue, 24 Aug 2010 06:50:09 +0000 (08:50 +0200)
committerFlorian Zeitz <florob@babelmonkeys.de>
Tue, 24 Aug 2010 18:17:25 +0000 (20:17 +0200)
js/main.js

index c20969d3d5a59c1e9e250eac5b5d993743aa522f..db4a0752d5a89aa8fde37348c49a309dec208c40 100644 (file)
@@ -102,6 +102,7 @@ function addForm(elem, x) {
             default:
                 item = $("<input/>");
             }
+                                               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");