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.

Unable to use 'condition'

See original GitHub issue

I am using angular2-json-schema-form and trying to make use of the ‘condition’ functionality. In the playground examples for ASF there is the ‘Hack: Conditional Required’ example:

{
  "schema": {
    "type": "object",
    "properties": {
      "switch": {
        "title": "Spam me, please",
        "type": "boolean"
      },
      "email": {
        "title": "Email",
        "type": "string",
        "pattern": "^\\S+@\\S+$",
        "description": "Email will be used for evil."
      }
    },
    "required": [
      "switch"
    ]
  },
  "form": [
    {
      "type": "help",
      "helpvalue": "<p>Schema Form does not support oneOf (yet), but you can do a workaround and simulate certain scenarios with 'condition' and 'required'  (and/or 'readonly') in the form.</p>"
    },
    "switch",
    {
      "key": "email",
      "condition": "model.switch",
      "required": true
    },
    {
      "key": "email",
      "condition": "!model.switch"
    },
    {
      "type": "submit",
      "style": "btn-info",
      "title": "OK"
    }
  ]
}

I have found that both fields are displayed, and the value of ‘condition’ appears to have no effect?

screenshot

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
sharanainapurapucommented, Feb 22, 2018

I actually wanted to show the second item only when the user clicks on No. At the same time I want the value of the No to be false. I was trying with negation, It did working. I used the above example and was able to fix it. Thank you @pdinesh80 !!

Issue:

        { 
          "key": "isLastDateOver", 
          "title": "Is last date over?", 
          "type": "radios",
          "inline": true,
          "titleInline": true,
          "titleMap": {
            "true": "Yes",        
            "false": "No"
          }
        }, 
        { 
          "key": "lastDate",
          "type": "date",
          "title": "Last Date",
          "condition": "!model.isLastDateOver",
          "required": true  
        }

Solution:

        { 
          "key": "isLastDateOver", 
          "title": "Is last date over?", 
          "type": "radios",
          "inline": true,
          "titleInline": true,
          "titleMap": {
            "true": "Yes",        
            "false": "No"
          }
        }, 
        { 
          "key": "lastDate",
          "type": "date",
          "title": "Last Date",
          "condition": {
            "functionBody":"try { return !model.isLastDateOver } catch(e){return false}"
          } 
        }
0reactions
pdinesh80commented, Dec 11, 2017

@dschnelldavis Condition works fine as from the example, have a question Can i use condition on string fields instead of boolean and check for expression? for example

{ “schema”: { “type”: “object”, “properties”: { “text”: { “title”: “Spam me, please”, “type”: “string” }, “email”: { “title”: “Email”, “type”: “string”, “pattern”: “^\S+@\S+$”, “description”: “Email will be used for evil.” } }, “required”: [ “switch” ] }, “form”: [ { “type”: “help”, “helpvalue”: “

Schema Form does not support oneOf (yet), but you can do a workaround and simulate certain scenarios with ‘condition’ and ‘required’ (and/or ‘readonly’) in the form.

” }, “switch”, { “key”: “email”, “condition”: “model.text==‘hello’”, “required”: true }, { “key”: “email”, “condition”: “model.text!=‘hello’”, }, { “type”: “submit”, “style”: “btn-info”, “title”: “OK” } ] }

UPDATE: From this link https://github.com/dschnelldavis/angular2-json-schema-form/issues/146, found a work around

so we can have condition like this

"condition":{
                        "functionBody":"try { return model.text=='test'} catch(e){return false}"
                    },

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to use condition in requirements.yaml #2111 - GitHub
yaml , I am unable to successfully disable a chart based on a known false boolean value. Replication steps: Download a chart with...
Read more >
Cannot create Condition for Flow - Power Platform Community
Solved: I'm creating a flow, but it will not let me add a value to the Condition to establish a relationship. The last...
Read more >
Unable to use conditional(when statement and with_file) for ...
If I am using the same condition for task, then it is working fine. debug: msg: "I am running..." when: "'myrole_1' in item"...
Read more >
Mental Health and the FMLA | U.S. Department of Labor
Assuming that you work for a covered employer and are eligible for FMLA leave, you may take leave if you are unable to...
Read more >
Congestive Heart Failure: Prevention, Treatment and Research
The best way to avoid congestive heart failure is to avoid the conditions that ... If you're unable to take an exercise test,...
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