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

conditional options #197

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

conditional options #197

wants to merge 5 commits into from

Conversation

xavitoro
Copy link

PR Type

What changes does this PR include (check all that apply)?
[ ] Bugfix
[x ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build process changes
[ ] Documentation changes
[ ] Other... please describe:

Does this PR introduce a breaking change?

[ ] Yes
[x ] No

Any other relevant information

This change is to add conditions to select component options, now we have two ways:

Example 1:
{
"key":"[yourkey]",
"type":"select",
"titleMap": [
{ "value": [value], "name": "[name]", "conditionKey": "[conditionKey1]"},
{ "value": "K843", "name": "CODE_K843", "conditionKey": "[conditionKey1]"},
{ "value": "L843", "name": "CODE_L843", "conditionKey": "[conditionKey2]"}
],
"conditionMap": [
{
"key": "[conditionKey1]",
"condition":{
"functionBody": "[functionBody1]"
}
},
{
"key": "[conditionKey2]",
"condition":{
"functionBody": "[functionBody2]"
}
}
]
}

Example 2:

{
"key":"[yourkey]",
"type":"select",
"titleMap": [
{ "value": [value], "name": "[name]",
"condition":{
"functionBody": "[functionBody1]"
}},
{ "value": "K843", "name": "CODE_K843",
"condition":{
"functionBody": "[functionBody1]"
}},
{ "value": "L843", "name": "CODE_L843",
"condition":{
"functionBody": "[functionBody2]"
}
}
]
}

@@ -92,4 +96,22 @@ export class SelectComponent implements OnInit {
updateValue(event) {
this.jsf.updateValue(this, event.target.value);
}

showOption(item: any, layoutNode: any): boolean {
if (item.conditionKey !== undefined && layoutNode.options.conditionMap !== undefined) {
Copy link

@johnedvard johnedvard Feb 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just wondering if it is equally correct to write if(item.conditionKey && layoutNode.options.conditionMap) skipping the !== undefined. I mean, if 0 and null are unacceptable values as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with what is best practice. If this is the style that goes through the rest of the code in this repo, then by all means, its better to keep it this way (using !== undefined).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right

@jscharett
Copy link
Contributor

This seems like a large change incorporating more than just conditional options. Specifically, the package.json and build changes seem like they should go into a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants