Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow custom controls to add one or more Option based attributes #1510

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 23 additions & 7 deletions docs/formBuilder/options/onAddOption.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ transform the optionTemplate by return a modified template using the `onAddOptio

## Usage

```javascript
/**
* Callback
* @param optionTemplate Template for new option, expect to be modified if required and returned
* @param {string} optionTemplate.label Option label
* @param {string} optionTemplate.value Option value
* @param {bool} optionTemplate.selected Mark option as selected
* @param optionInfo Details about the option field
* @param {string} optionInfo.type Control type
* @param {string} optionInfo.index Index of new option
* @param {bool} optionTemplate.isMultiple Does the attribute have multiple selections allowed
* @param {bool} optionTemplate.fieldName Name of the field these options are associated with.
*/
onAddOption: (optionTemplate, optionInfo)
```

```javascript
const options = {
onAddOption: (optionTemplate, optionIndex) => {
optionTemplate.label = `Option ${optionIndex + 1}`
optionTemplate.value = `option-${optionIndex + 1}`
onAddOption: (optionTemplate, optionInfo) => {
optionTemplate.label = `Option ${optionInfo.index + 1}`
optionTemplate.value = `option-${optionInfo.index + 1}`
return optionTemplate
},
}
Expand All @@ -19,10 +35,10 @@ To add additional data with specific options, for example, to use with business

```javascript
const options = {
onAddOption: (optionTemplate, optionIndex) => {
optionTemplate.label = `Option ${optionIndex.index + 1}`
optionTemplate.value = `option-${optionIndex.index + 1}`
optionTemplate.minLevel = `min-level-${optionIndex.index + 1}`
onAddOption: (optionTemplate, optionInfo) => {
optionTemplate.label = `Option ${optionInfo.index + 1}`
optionTemplate.value = `option-${optionInfo.index + 1}`
optionTemplate.minLevel = `min-level-${optionInfo.index + 1}`

return optionTemplate
}
Expand Down