Hi Mauricio,
I can definitely see why that might be useful ;)
The API on that piece could use some polish, but the latest demo (we will be pushing to the website soon) has an example of how to push data into a TextBoxList, but here's something I think should work for you:
From what I can tell, you want to incorporate it as part of a form where users may select options, and those options will persist across the form submit.
The way we handle this in Liferay is to push the entries to a hidden input that are comma-separated.
So let's say you want to add new entries into your TextBoxList, I'm assuming that you've stored the entries in a comma separated list on a hidden input like so:
1<input name="hiddenInput" id="hiddenInput" value="test1,test2,test3" />
Then, you could create your TextBoxList like in the demo:
1var TBL = new A.TextboxList(
2 {
3 dataSource: [
4 ['NM', 'New Mexico', 'Land of Enchantment'],
5 ['NY', 'New York', 'Empire State'],
6 ['NC', 'North Carolina', 'First in Freedom'],
7 ['ND', 'North Dakota', 'Peace Garden State'],
8 ['OH', 'Ohio', 'The Heart of it All'],
9 ['OK', 'Oklahoma', 'Oklahoma is OK'],
10 ['OR', 'Oregon', 'Pacific Wonderland'],
11 ['PA', 'Pennsylvania', 'Keystone State'],
12 ['RI', 'Rhode Island', 'Ocean State']
13 ],
14 schema: {
15 resultFields: ['name']
16 },
17 matchKey: 'name',
18 typeAhead: true,
19 contentBox: '#myAutoComplete',
20 width: 600
21 }
22);
23
24TBL.render('#demo');
Then you could prefill it with values from the hidden input like so:
1var values = A.one('#hiddenInput').val().split(',');
2
3A.each(values, TBL.add, TBL);
Basically, every TextBoxList widget as an add, insert, and remove method that will let you manipulate the entries in there.
Now the question is, how to get the values back into the hidden input?
All TextBoxLists have an underlying DataSet object that is stored as an "entries" property.
You could do it one of two ways, depending on how you're submitting your form. If you're submitting your form like normal, you can just update the hidden form on submit, like so:
1A.one('#form').on('submit', function(event) {
2A.one('#hiddenInput').val(TBL.entries.keys.join());
3});
If you're submitting the form field via ajax, or want to update it every time an item is added or removed from the entry box, you can do this:
1var updateHiddenInput = function(event){
2A.one('#hiddenInput').val(TBL.entries.keys.join());
3}
4
5TBL.entries.after('add', updateHiddenInput);
6TBL.entries.after('remove', updateHiddenInput);
I hope that helps, but let me know if you have any other questions
Please sign in to flag this as inappropriate.