Dynamic data lists in CQ5
Monday 10 October 2011 at 12:00 The author-mode edit dialogues in CQ5 are great especially if you populate them with your own options for dropdown lists. If you have a nice handy JSON data source which is conveniently organised into key/value pairs, you can use this in your CQ5 author dialogues to provide the values for dropdowns, combo boxes, and lists of radio buttons and checkboxes. It's very easy if you data that looks something like this:
{"mydata":[
{"id":"1","label":"one"},
{"id":"2","label":"two"},
{"id":"3","label":"three"},
{"id":"4","label":"four"},
{"id":"5","label":"five"},
{"id":"6","label":"six"}
]}
when you create the edit control in the dialog, set these properties and it will load the remote data and use it
optionsProvider = URL optionsRoot = 'mydata' optionsLabelField = 'label' optionsValueField = 'id' xtype = 'selection' type = 'select' [or radio, checkbox, combo]
along with all the usual properties, and it should show your data labels in the drop down, and store the values in the repository. There are some caveats as noted in the documentation, mostly that the data needs to be HTML entity encoded or escaped otherwise < and > do bad things. It's also not clear how to unselect it and have no option in the saved data, so you might need to design the dialog with this in mind. Finally, the defaults for the checkboxes are somewhat questionable.
