lib/kolab_client_task.php lib/kolab_form.php public_html/js

Aleksander Machniak machniak at kolabsys.com
Thu Mar 22 14:33:01 CET 2012


 lib/kolab_client_task.php     |    6 ++++++
 lib/kolab_form.php            |    4 ++++
 public_html/js/kolab_admin.js |   17 +++++++++--------
 3 files changed, 19 insertions(+), 8 deletions(-)

New commits:
commit f67428d5163af64c92ad8c01a8ef9ce1e1040a4b
Author: Aleksander Machniak <alec at alec.pl>
Date:   Thu Mar 22 14:32:08 2012 +0100

    Support multiselect fields with fix for form serialization

diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index dd5a304..25443f2 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -617,6 +617,7 @@ class kolab_client_task
 
         switch ($field['type']) {
         case 'select':
+        case 'multiselect':
             if (!isset($field['values'])) {
                 $data['attributes'] = array($field['name']);
                 $resp = $this->api->post('form_value.select_options', null, $data);
@@ -635,6 +636,11 @@ class kolab_client_task
             else {
                 $result['options'] = array('');
             }
+
+            if ($field['type'] == 'multiselect') {
+                $result['multiple'] = true;
+            }
+
             break;
 
         case 'list':
diff --git a/lib/kolab_form.php b/lib/kolab_form.php
index a21c758..f5533af 100644
--- a/lib/kolab_form.php
+++ b/lib/kolab_form.php
@@ -284,6 +284,10 @@ class kolab_form
             break;
 
         case self::INPUT_SELECT:
+            if (!empty($attribs['multiple']) && empty($attribs['size'])) {
+                $attribs['size'] = 5;
+            }
+
             $content = kolab_html::select($attribs, true);
             break;
 
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index ad2f6bc..dabf56c 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -906,16 +906,17 @@ function kolab_admin()
       if (v = $('[name="'+extra[i]+'"]', form).val())
         json[extra[i]] = v;
 
-    this.form_serialize({id: id, json: json});
-/*
-    // convert values of list elements to array type
-    $('textarea[data-type="list"]', form).each(function() {
+    // serializeArray() doesn't work properly for multi-select
+    $('select[multiple="multiple"]', form).each(function() {
       var name = this.name;
-      // maybe already converted by skin engine
-      if (!json[name] || !$.isArray(json[name]))
-        json[name] = $(this).val().split("\n");
+      json[name] = [];
+      $(':selected', this).each(function() {
+        json[name].push(this.value);
+      });
     });
-*/
+
+    this.form_serialize({id: id, json: json});
+
     return json;
   };
 





More information about the commits mailing list