question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[support] make a field depend on multiple fields

See original GitHub issue

I want to perform an http request to get a field’s options, but only when other fields have values, other fields may get theirs options by HTTP requests

example:

fields= [
 { key: 'field1', type:'select', templateOptions:{options: http.get('/field1')},
 { key: 'field2', type:'select', templateOptions:{options: http.get('/field2')},
{
 key: 'field3',
 dependencies: ['field1', 'field2'] // <-------------------
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aitboudadcommented, Sep 14, 2022

Another solution is to rely on fieldChanges which emit the field options when they got resolved (https://github.com/ngx-formly/ngx-formly/issues/2350#issuecomment-658158267) but you should declare options in expressionProperties instead:

fields= [
 { key: 'field1', type:'select', expressionProperties:{'templateOptions.options': http.get('/field1')},
 ...
 {
      key: 'field3',
      hooks: {
        onInit: field => {
          field.templateOptions.options = field.options.fieldChanges....
        }
      }
 }
]
1reaction
aitboudadcommented, Sep 14, 2022

do you mean that service.get('/field3') is of type Observable or Promise instead of object?

Observable type

I see it like:

get(field:string, dependencies: string[]){
  return new Observable(sub=>{
      /* wait until all dependencies have values */
  })

yes something like that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I make a field dependent on multiple fields in EDC/CDMS?
When creating or editing a field, it is possible to make it dependent on only one field. However, using hidden calculation fields, you...
Read more >
Multi level field dependencies - IdeaExchange - Salesforce
Ah, yes, making a field dependent on multiple controlling fields is not possible. I will add this to my product backlog for consideration....
Read more >
One field is dependent on two fields - ServiceNow Community
Hi, I have category and subcategory choice fields on change form. subcategory field values depends on both type and category choice fields.
Read more >
Dependent field setup based on multiple fields - DataTables
Hi, All the dependent api examples pull in one fields value and then you make decisions based on it that can effect other...
Read more >
creating multiple field dependencies - Atlassian Community
we are working to get other teams on to Jira Service Desk. One of the questions they asked is how extensively we can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found