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 Conditions to set form values

See original GitHub issue

Scope: FormRender, Conditions

Description

User may often want to use a condition to not only (optionally) evaluate the display criteria for a form field, but to also (optionally) set a form value. For example, if there is a simple 3 field form - field A is a number, field B is a string and field C should have its value set based on a set of conditions on both A and B.

This feature should accomodate the ability to

  • evaluate a condition and set a form field without changing the visibility of the field
  • evaluate a condition and set a form field and change the visibility of the field
  • support hidden, but enabled fields

Semantics / Syntax Suggestion

<u>Evaluate a condition and set a form field without changing the visibility of the field</u>

{
  fields: [
    {
      name: 'Foo', // controlled field
      component: 'text-field',
      condition: {   // <-- new keyword 
        when: 'BarFoo', // name of controlled field
        is: 'Bar',      // condition
        remainVisible: true // remain visible (default)
        then: [{ // <-- absense of the "set" keyword means to set this field
          to: 'I have been set because BarFoo = Bar' // value to set
        },
        {
	 set: 'Woo',                                // name of field to set
          to: 'I have been set because BarFoo = Bar' // value to set
        }]
      }
    }, 
    {
      name: 'Woo', // controlled field
      component: 'text-field',
    },
    {
      name: 'BarFoo',
      label: 'Foo is Bar!',
      component: 'text-field',
    }
  ]
}

<u>Evaluate a condition and set a form field and change the visibility of the field</u>

{
  fields: [
    {
      name: 'Foo', // controlled field
      component: 'text-field',
      condition: {   // <-- new keyword 
        when: 'BarFoo', // name of controlled field
        is: 'Bar',      // condition
        remainVisible: false // become visible when condition is met and set fields
        then: [{ // <-- absense of the "set" keyword means to set this field
          to: 'I have been set because BarFoo = Bar' // value to set
        }]
      }
    }, 
    {
      name: 'Woo', // controlled field
      component: 'text-field',
    },
    {
      name: 'BarFoo',
      label: 'Foo is Bar!',
      component: 'text-field',
    }
  ]
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
mteichtahlcommented, May 15, 2020

This is brilliant. We are integrating in our next sprint

Sent from my iPhone

On May 15, 2020, at 8:53 PM, Richard Všianský notifications@github.com wrote:

@mteichtahl Since there is no activity here, we are closing this issue. Please feel free to re-open, if the solution is not sufficient.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

1reaction
mteichtahlcommented, Apr 17, 2020

I have just reviewed the documentation.

Thank you so much. We look to test this next week

Sent from my iPhone

On Apr 17, 2020, at 6:23 PM, Martin Maroši notifications@github.com wrote:

@mteichtahl the feature has been merged and the next version (2.1) should be available shortly with some examples in the docs.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I add conditions to my form? - formtitan support
3-, Press on "Set conditions" ; 4-, When the window will open you will need to configure the rules of your condition: ;...
Read more >
<input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >
Setting form field show/hide conditions - Adobe Support
To set a condition on a field in the drag-and-drop editing environment, right-click the field and select Edit, or double-click the field. The ......
Read more >
Conditional Form Fields | Form API - Drupal
Show or hide, enable, disable or require form fields based on values of other fields using the #states property of form render arrays....
Read more >
Add condition to a html form` - Stack Overflow
This will force the user to submit exactly the letter "a" as name (just an example of course! You should write a more...
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