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.

Allow to hide/show inputs when a boolean is toggled

See original GitHub issue

Let’s say I have this form:

[ ] Enable SMS? (Boolean)
[ ] Phone Number Required (Boolean)

But I only want to present the Phone Number Required when the Enable SMS is true because otherwise, the input doesn’t make sense.

My first thought at schema level would be something like:

"enable_sms": {
  "type": "boolean"
},
"require_phone_number": {
  "type": "boolean",
  "x-render-only-if": "enable_sms"
}

Or something in that sense, the property would specify the one that needs to be “true” to render it.

I’m simplifying here with two inputs but our case includes half a dozen fields that could be hidden.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
albanmcommented, Jan 14, 2021

I just published the conditional subschema functionality, please have a look here.

I marked it as beta as I still need to think about it and maybe reconsider the implementation. But for simple use-cases like a boolean switch it is safe to use it.

0reactions
sobrinhocommented, Jan 20, 2021

Oh, I see! I didn’t check that the if/then/else was in the JSON spec, in that case, makes more sense to follow it. Thanks! ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hide, show input using toggle jquery boolean - Stack Overflow
I get input from dropdown list and depending on what user chose I want to show/hide different inputs. I have tried using toggle...
Read more >
Hide/Show properties dynamically in inspector. - Unity Answers
This creates a toggle that displays similarly to how the Inspector shows a bool field by default. Next I will create a group...
Read more >
.toggle() | jQuery API Documentation
A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7,...
Read more >
How to Show Hide or Toggle Elements in Angular
I am sharing a simple example here in this post showing how to toggle or show and hide elements in Angular. Let us...
Read more >
Collapse - Bootstrap
Collapse. Toggle the visibility of content across your project with a few classes and our JavaScript plugins. Example. Click the buttons below to ......
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