Changeset 1375
- Timestamp:
- 20/11/09 14:04:04 (3 months ago)
- Files:
-
- trunk/modules/kauri-forms/kauri-forms-extra/src/main/kauri/static/autocomplete/js/autocomplete.js (modified) (5 diffs)
- trunk/samples/kauri-forms-sample/src/main/kauri/pages/autocomplete-control.html.xml (modified) (3 diffs)
- trunk/samples/kauri-forms-sample/src/main/kauri/pages/basic-controls1.html.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/modules/kauri-forms/kauri-forms-extra/src/main/kauri/static/autocomplete/js/autocomplete.js
r1372 r1375 28 28 $.extend(AutocompleteControl.prototype.elements, { 29 29 input : { 30 /* Kauri Forms needs an input-role element, but we don't , therefore30 /* Kauri Forms needs an input-role element, but we don't (want to use the 'input' role), therefore 31 31 simply create a hidden div. */ 32 32 create : "<div style='display:none'/>" … … 47 47 var me = this; 48 48 49 var inputTemplate = new kp.UriTemplate(this.inputTemplate, {skipEscape: true}); 50 var listTemplate = new kp.UriTemplate(this.listTemplate, {skipEscape: true}); 51 var valueTemplate = new kp.UriTemplate(this.valueTemplate, {skipEscape: true}); 49 this.inputTemplate = new kp.UriTemplate(this.inputTemplate, {skipEscape: true}); 50 this.listTemplate = new kp.UriTemplate(this.listTemplate, {skipEscape: true}); 52 51 53 52 var jqOptions = { … … 56 55 var parsed = []; 57 56 for (var i=0;i<data.length;i++) { 58 parsed.push({ data: data[i], value: valueTemplate.expand(data[i], true), result:inputTemplate.expand(data[i], true)});57 parsed.push({ data: data[i], value: data, result: me.inputTemplate.expand(data[i], true)}); 59 58 } 60 59 return parsed; 61 60 }, 62 61 formatItem: function(data, current, last) { 63 return listTemplate.expand(data, true);62 return me.listTemplate.expand(data, true); 64 63 } 65 64 }; … … 69 68 70 69 $acinput.autocomplete(this.dataUri, jqOptions).bind("result", function(event, objData, valueData) { 71 me.setValue( valueData);70 me.setValue(objData); 72 71 }); 73 72 … … 88 87 89 88 AutocompleteControl.prototype.setValue = function(value) { 90 // FIXME: implement?91 89 this["<super.call>"]("setValue", [value]); 90 if (value === undefined) { 91 $acinput.val(); 92 } else { 93 //$acinput.val(this.inputTemplate.expand(value, true)); 94 } 95 } 96 97 AutocompleteControl.prototype.getWireValue = function() { 98 var t = this.getValue(); 99 var s = JSON.stringify(t); 100 return JSON.stringify(this.getValue()); 101 } 102 103 AutocompleteControl.prototype.setWireValue = function(wireValue) { 104 if (wireValue === undefined) { 105 this.setValue(undefined); 106 $acinput.val(''); 107 } else { 108 this.setValue(JSON.parse(wireValue)); 109 $acinput.val(this.inputTemplate.expand(this.getValue(), true)); 110 } 92 111 } 93 112 trunk/samples/kauri-forms-sample/src/main/kauri/pages/autocomplete-control.html.xml
r1370 r1375 19 19 "base": "autocomplete-control", 20 20 "dataUri": "${publicUri('service:/data/contact/')}", 21 "valueTemplate": "value:{id}",22 21 "inputTemplate": "input:{id} - {name}", 23 22 "listTemplate": "list:{id} - {name} {email}" … … 29 28 $(function() { 30 29 var form1 = new jQuery.org.kauriproject.forms.Form("form1", fconf); 30 window.form1 = form1 31 31 }) 32 32 </script> … … 45 45 </fieldset> 46 46 </form> 47 48 <!--49 <h3>jquery (no control)</h3>50 51 Select a contact: <input type="text" id="jq-contact"/>52 <script>53 $(function() {54 55 var kp = $.org.kauriproject;56 var inputTemplate = new kp.UriTemplate("{email}");57 var listTemplate = new kp.UriTemplate("{id} - {email})");58 var valueTemplate = new kp.UriTemplate("{id}");59 60 $("#jq-contact").autocomplete("${publicUri('service:/data/contact')}", {61 dataType: "json",62 parse: function(data) {63 var parsed = [];64 for (var i=0;i<data.length;i++) {65 parsed.push({ data: data[i], value: valueTemplate.expand(data[i], true), result: inputTemplate.expand(data[i], true)});66 }67 return parsed;68 },69 formatItem: function(data, current, last) {70 return listTemplate.expand(data, true);71 }72 }).bind("result", function(event, objData, valueData) {73 alert('You selected ' + valueData);74 });75 });76 </script>77 -->78 47 </t:block> 79 48 trunk/samples/kauri-forms-sample/src/main/kauri/pages/basic-controls1.html.xml
r1374 r1375 108 108 </tr> 109 109 <tr> 110 <td><label kauri-role="label" kauri-idref="tip-of-the-day "/></td>111 <td><span style="width:200px;height:150px" kauri-idref="tip-of-the-day " kauri-role="input"/></td>112 <td><span kauri-idref="tip-of-the-day " kauri-role="messages"/></td>110 <td><label kauri-role="label" kauri-idref="tip-of-the-day1"/></td> 111 <td><span style="width:200px;height:150px" kauri-idref="tip-of-the-day1" kauri-role="input"/></td> 112 <td><span kauri-idref="tip-of-the-day1" kauri-role="messages"/></td> 113 113 </tr> 114 114 <tr>
