Last active
January 12, 2023 16:41
-
-
Save ipeychev/9267761 to your computer and use it in GitHub Desktop.
Example usage of AutoCompleteInput in Liferaty Portal 7 (aka master right now)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* For the UI, it is using the awesome AutoComplete from http://yuilibrary.com/yui/docs/autocomplete/ | |
* All the documentation you can find there, for example to retrive the data via AJAX, DataSource, etc. is valid here too. | |
* Also, options, specific to AutoComplete from YUI you can pass via 'acConfig.the-attribute-here'. Look at 'acConfig.resultFormatter' below. | |
*/ | |
<aui:input name="test123" type="textarea" with="300" height="400" value=""/> | |
<aui:script use="liferay-autocomplete-input"> | |
var lacInput = new Liferay.AutoCompleteInput( | |
{ | |
'acConfig.resultFormatter': function() {}, // allows you to create your own resultFormatter. In most of the cases you will omit this, usually tplResults (see the last attribute) will be enough | |
'acConfig.resultTextLocator': 'text', // allows you to specify a resultTextLocator | |
inputNode: '#<portlet:namespace />test123', // the input element we have to autocomplete | |
source: [ // example data, in this case it is a simple array, but you can easily retrieve the data via AJAX, for example. | |
{ | |
text: 'chema', | |
name: 'chema' | |
}, | |
{ | |
text: 'iliyan', | |
name: 'iliyan' | |
}, | |
{ | |
text: 'carlos', | |
name: 'carlos' | |
}, | |
{ | |
text: 'carlos1', | |
name: 'carlos1' | |
}, | |
{ | |
text: 'carlos2', | |
name: 'carlos2' | |
}, | |
{ | |
text: 'migue', | |
name: 'migue' | |
}, | |
{ | |
text: 'miguel', | |
name: 'miguel' | |
}, | |
{ | |
text: 'jose', | |
name: 'jose' | |
} | |
], | |
tplResults: '<div>{name}</div>'// the template of the results as they will appear for the user | |
} | |
); | |
</aui:script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment