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 fields

See original GitHub issue

It would be great to have conditional fields. The value of one field influence others visibility (and maybe more ?). For example, I check a checkbox field, and it show another field. It could allow for very dynamic forms. The field would need some sort of meta information about them, for example:

/*schema.js*/
fields: [{
    type: "switch",
    label: "Add a packaging ?",
    model: "packet"
}, {
    type: "select",
    label: "packet type",
    model: "packet_type",
    required: true,
    values: [
            { id: "standard", name: "Standard" },
            { id: "present", name: "Present" }
        ]
    // Only appear if packet value is true
    dependOn: [{ model: "packet", value: true }]
}, {
    type: "text",
    label: "message to write on the note",
    model: "present_note",
    // Only appear if packet_type selected value of "id" field is "present" AND if packet value is true
    dependOn: [{ model: "packet_type", field: "id", value: "present" }, { model: "packet", value: true }]
}]

They could be option for “not this value” and “multiple good values”. Internally, it could use v-show on a computed value that we could add in abstractField.js. That’s just some first ideas and thoughts, please tell me what are you think about that.

Issue Analytics

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

github_iconTop GitHub Comments

12reactions
icebobcommented, Aug 11, 2016

This is an exist function. Check the company.name field in dev example. You can set a visible function what lib will execute.

{
            type: "text",
            label: "Company name",
            model: "company.name",
            styleClasses: ["company", "half-width"],

            visible(model) {
                return model && model.type == "business";
            }
        }

So this fields is visible if the model.type is “business”.

I see it is missing from docs

2reactions
eyleroncommented, Feb 27, 2019

Wouldn’t it be nice to have a declarative way to indicate the dependency, like all the rest of the schema is, instead of functional?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional Fields | Drupal.org
Conditional Fields allows you to manage sets of dependencies between fields. When a field is “dependent”, it will only be available for editing ......
Read more >
Conditional Fields for Contact Form 7 - WordPress.org
This plugin adds conditional logic to Contact Form 7. If you edit your CF7 form, you will see an additional tag called “Conditional...
Read more >
Conditional Fields - DocuSign Support
Conditional fields allow you to create dynamic documents that support a conditional work flow. Conditional fields only appear to the recipient ...
Read more >
Understanding Conditional Field Logic - iCIMS Community
Through Conditional Field Logic, user admins can control which profile fields are displayed—and which options are listed for those fields—based on how other ......
Read more >
Conditional Fields
With the Conditional Fields macro, you can specify different conditions to customize the form. This is useful for creating dynamic forms that react...
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