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.

Conditional loading of fields in template UI for Radio button

See original GitHub issue

Hi, I need to load the below react json schema component (conditional field) in template UI:

{
  "title": "Schema dependencies",
  "description": "These samples are best viewed without live validation.",
  "type": "object",
  "properties": {    
    "conditional": {
      "title": "Conditional",
      "$ref": "#/definitions/person"
    }
  },
  "definitions": {
    "person": {
      "title": "Person",
      "type": "object",
      "properties": {
        "Do you have any pets?": {
          "type": "string",
          "enum": [
            "No",
            "Yes: One",
            "Yes: More than one"
          ],
          "default": "No"
        }
      },
      "required": [
        "Do you have any pets?"
      ],
      "dependencies": {
        "Do you have any pets?": {
          "oneOf": [
            {
              "properties": {
                "Do you have any pets?": {
                  "enum": [
                    "No"
                  ]
                }
              }
            },
            {
              "properties": {
                "Do you have any pets?": {
                  "enum": [
                    "Yes: One"
                  ]
                },
                "How old is your pet?": {
                  "type": "number"
                }
              },
              "required": [
                "How old is your pet?"
              ]
            },
            {
              "properties": {
                "Do you have any pets?": {
                  "enum": [
                    "Yes: More than one"
                  ]
                },
                "Do you want to get rid of any?": {
                  "type": "boolean"
                }
              },
              "required": [
                "Do you want to get rid of any?"
              ]
            }
          ]
        }
      }
    }
  }
}

Any suggestions on how to convert this to template.yaml file?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sharadpattanshetticommented, Dec 17, 2021

Thanks @defaultbr. I got this one working for the dropdown (select) on the UI. I was looking for Radio button option hence tried adding ui:widget: radio to the yaml. In React Json Schema form it renders as radio button with dependencies however when converted to YAML it does not work. Radio button along with $ref dependencies does not render when added in YAML format

1reaction
defaultbrcommented, Dec 14, 2021

@sharadpattanshetti you could test this example

  parameters:
    - title: Creating a API
      required: []
      properties:
        technology:
          type: string
          enum:
            - java
            # - dotnet
            - javascript
            - python

      # Creating a dependency based on the selected technology above
      dependencies:
        technology:
          oneOf:
            - properties:
                technology:
                  enum:
                    - java
                java version:
                  type: "string"
                  enum:
                    - java8
                    - java11

              # Creating a dependency based on the selected java version (not necessary, just for example)
              dependencies:
                java version:
                  oneOf:
                    - properties: 
                        java version:
                          enum:
                            - java8
                        any other option:
                          type: "string"
                          enum:
                            - option1
                            - java build x.y.z
              required: 
                - java version

What I have learned testing the above yml code:

  1. Segregate the template in more software catalog, don’t try to merge multiple languages and things to consider in one file, this will make your template a big, very very big and confuse spaghetti.

  2. dependency are coupled in the field title/name, so try to use simple names

  3. You can’t import (use the $include) external files, so you will return to item 1 above if you plan to consolidate a lot of questions and if’s inside a single template file

Maybe a good use will be to create a catalog entry for Libraries, another for API’s, etc…

If you create a Api and can have deploy in multiple targets, like in kubernetes, azure, aws, gcp, I guess it’s better to have different catalog entry for each one, since you can ask a lot of different things for each option and your template will be hard to read.

Examples:

  • Create Api - ON PREM K8S
  • Create Api - AWS
  • Create Api - GCP
  • Create Api - Serverless - Lambda (AWS)
  • Create Api - Serverless - Azure Functions (AWS)

(of course, if each one has different requirements and fields)

Maybe I’m totally wrong, since I learned this almost 30 minutes ago, if i find a way to consolidate and avoid a huge spaguetti, I will post here again

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exposing Additional Form Fields via Checked Radio Buttons
Weird Quirk. Becca Rice wrote in to tell me that there is a bug with the CSS stuff that reveals the additional fields...
Read more >
DocuSign Radio button conditional field - Stack Overflow
The DocuSign documentation says "You can apply conditional logic to the following field types:Checkbox, Radio Button, Drop-down,Text".
Read more >
Is it possibile to show fields based on radio button selections?
I trying to make a radio button panel, that have 2 options, ... Conditional Logic: Is it possibile to show fields based on...
Read more >
Radio Buttons Fieldtype — ExpressionEngine 6 Documentation
Radio Buttons allow users to choose a single item from a list of options. ... The short name of a field is used...
Read more >
Radio button requires two clicks to "check" even though ...
I am working on a component that has a simple 2 option radio group. I want to show and hide a div (template...
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