Select2
The select2 field is a very powerfull dropdown field.
It get its items from a webapi call using the DNN serviceFramemork.
schema type : string, (and array for checkbox list in dropdown)
options type : select2
Example 1 - Getting Additional data
Additional data are small data lists that you want to use in a template. Typical examples: categories, tags.
"type": "select2",
"dataService": {
"action": "LookupData",
"data": {
"dataKey": "Categories",
"valueField": "Id",
"textField": "Title"
}
}
The above example in an option.json file will result in a dropdown of categories as defined in the Manifest, with fields Id and Title. When selecting a certain Title, the Id will be saved.
Both Id and Title will become available in the Model of the template, so not just the Id.
Getting items from another OC module
You can mimic (one way) relations in OpenContent simply by defining a select2 field in the option.json file that points to another module.
"type": "select2",
"dataService": {
"data": {
"moduleId": "123",
"tabId": "456",
"valuefield": "Id",
"textfield": "Name"
},
"action":"Lookup"
}
The above example in an option.json file will result in a dropdown of named items from module 123 (of Tab 456). When selecting a certain Name, the Id will be saved.
The whole object of the selected item will become available in the Model of the template, so not just the Id.
Example 3 - Custom API call
You can also create your own API call in your own module
"type": "select2",
"dataService": {
"data" : {},
"module" : "YourFriendlyModuleName",
"controller":"MyModuleAPI",
"action":"Lookup"
}
To get the data, this field does an ajax post with the dnn serviceframework.
module = dnn module with a web api route defined
controller = webapi controller name
action = method on the web api controller
data : data passed as parameters to the web api controller
Here a web api controller example (look at Lookup method)
https://github.com/sachatrauwaen/OpenContent/blob/master/Components/OpenContentAPIController.cs
Updated over 6 years ago