web/data/cubicweb.widgets.js
branchstable
changeset 4901 19ecbbc4f633
parent 4738 6cca4f602486
child 5453 d0c8076e298b
child 5767 1d811df051c2
equal deleted inserted replaced
4900:29626bb6071b 4901:19ecbbc4f633
   111     __init__ : function(node) {
   111     __init__ : function(node) {
   112 	Widgets.SuggestField.__init__(this, node, {mustMatch: true});
   112 	Widgets.SuggestField.__init__(this, node, {mustMatch: true});
   113     }
   113     }
   114 
   114 
   115 });
   115 });
   116 
   116 //remote version of RestrictedSuggestField
       
   117 Widgets.LazySuggestField = defclass('LazySuggestField', [Widgets.SuggestField], {
       
   118     __init__: function(node, options) {
       
   119 	var self = this;
       
   120 	var multi = "no";
       
   121 	options = options || {};
       
   122 	options.max = 50;
       
   123 	options.delay = 50;
       
   124 	options.cacheLength=0;
       
   125 	options.mustMatch = true;
       
   126         // multiple selection not supported yet (still need to formalize correctly
       
   127         // initial values / display values)
       
   128         var initialvalue = evalJSON(node.getAttribute('cubicweb:initialvalue') || 'null');
       
   129         if (!initialvalue) {
       
   130             initialvalue = node.value;
       
   131         }
       
   132         options = jQuery.extend({dataType: 'json',
       
   133                                  multiple: (multi == "yes") ? true : false,
       
   134                                  parse: this.parseResult
       
   135                                 }, options);
       
   136         var dataurl = node.getAttribute('cubicweb:dataurl');
       
   137         // remove 'name' from original input and add the hidden one that will
       
   138         // store the actual value
       
   139         var hidden = INPUT({'type': "hidden", 'name': node.name, 'value': initialvalue});
       
   140         node.parentNode.appendChild(hidden);
       
   141         jQuery(node).bind('result', {hinput: hidden, input:node}, self.hideRealValue)
       
   142             .removeAttr('name').autocomplete(dataurl, options);
       
   143     },
       
   144 
       
   145 
       
   146     hideRealValue: function(evt, data, value) {
       
   147 	if (!value){
       
   148 	    value="";
       
   149 	}
       
   150         evt.data.hinput.value = value;
       
   151     },
       
   152 
       
   153     /*
       
   154      * @param data: a list of couple (value, label) to fill the suggestion list,
       
   155      *              (returned by CW through AJAX)
       
   156      */
       
   157     parseResult: function(data) {
       
   158         var parsed = [];
       
   159         for (var i=0; i < data.length; i++) {
       
   160                 var value = ''+data[i][0]; // a string is required later by jquery.autocomplete.js
       
   161                 var label = data[i][1];
       
   162                 parsed[parsed.length] = {
       
   163                     data: [label],
       
   164                     value: value,
       
   165                     result: label
       
   166                 };
       
   167         };
       
   168         return parsed;
       
   169     }
       
   170 
       
   171 });
   117 
   172 
   118 /*
   173 /*
   119  * suggestform displays a suggest field and associated validate / cancel buttons
   174  * suggestform displays a suggest field and associated validate / cancel buttons
   120  * constructor's argumemts are the same that BaseSuggestField widget
   175  * constructor's argumemts are the same that BaseSuggestField widget
   121  */
   176  */