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

Enum source remote URL of one property depending on value of other property #219

Open
tjeerdbakker38 opened this issue Dec 18, 2020 · 4 comments

Comments

@tjeerdbakker38
Copy link

tjeerdbakker38 commented Dec 18, 2020

Hi all,

I'm trying to implement the following using ncform. I need a form in which the possible choices for one dropdown depend on the value of another dropdown. For instance, the first dropdown would contain a list of projects, and the second a list of branches and tags for the project selected in the first dropdown.

I've adapted the adv-temp-value example to make the remoteUrl a dx expression using {{$temp.selectedItem.id}} to build the proper URL, but it seems that remoteUrl isn't recalculated when the first property changes value. Or at least, the URL containing the values for the second dropdown is never downloaded. Please find my ncform schema below. Do you have any suggestions how to implement the proper behaviour?

Many thanks for any help!

{
  type: "object",
  properties: {
    "choice": {
      "type": "string",
      "ui": {
        "description": "dx: {{$temp.selectedItem.desc}}",
        "widget": "select",
        "widgetConfig": {
          "itemDataKey": "selectedItem",
          "enumSourceRemote": {
            remoteUrl: "data.json",
            refField: ""
          }
        }
      }
    },
    "sub": {
      "type": "string",
      "ui": {
        "widget": "select",
        "widgetConfig": {
          "enumSourceRemote": {
            remoteUrl: "dx: {{$temp.selectedItem.id}} + '/sub.json'",
            refField: ""
          }
        }
      }
    }
  }
}
@daniel-dx
Copy link
Collaborator

Try this:

{
  type: "object",
  properties: {
    "choice": {
      "type": "string",
      "ui": {
        "description": "dx: {{$temp.selectedItem.desc}}",
        "widget": "select",
        "widgetConfig": {
          "itemDataKey": "selectedItem",
          "enumSourceRemote": {
            remoteUrl: "data.json",
            refField: ""
          }
        }
      }
    },
    "sub": {
      "type": "string",
      "ui": {
        "widget": "select",
        "widgetConfig": {
          "enumSourceRemote": `dx: ({
            remoteUrl: "dx: {{$temp.selectedItem.id}} + '/sub.json'",
            refField: ""
          })`
        }
      }
    }
  }
}

@tjeerdbakker38
Copy link
Author

Hi Daniel, thanks for your suggestion. Unfortunately, this doesn't trigger a refresh of the list of options for 'sub' when the users selects an option for 'choice'. Is there anything else I can try?

@daniel-dx
Copy link
Collaborator

@tjeerdbakker38
Copy link
Author

Thank you, that is a good workaround.

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

No branches or pull requests

2 participants