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.

Valid feedback and invalid feedback

See original GitHub issue

Is your feature request related to a problem? Please describe. I am trying to use Bootstrap form validation together with react-bootstrap-typeahead using form feedback divs. Bootstrap toggles visibility of feedback components based on classes of sibling form-control element. If I am adding the feedback as I do usually with regular inputs:

<Typeahead {...someProps} isInvalid/>
<div class="invalid-feedback">The value you have entered is terrible!</div>

the feedback is not shown because .invalid-feedback is not a sibling to RBT .form-control (.form-control is wrapped with .rbt-input-hint-container). It is not possible (as far as I know) to describe this DOM relationship with CSS (to toggle .invalid-feedback visibility based on RBT DOM).

Describe the solution you’d like It would be nice to have validFeedback/invalidFeedback properties in <Typeahead/> component. RBT can add this feedback elements near the input.form-control. Probably the same logic should apply for validTooltip/invalidTooltip.

Describe alternatives you’ve considered With the current state of RBT this can be worked around as follows (using a wrapper component):

// JS
    render() {
        return <>
                <Typeahead
                    {...someProps}
                    isValid={this.props.isValid}
                    isInvalid={this.props.isInvalid}
                />
            {
                this.props.isValid && this.props.validFeedback ?
                    <div className="valid-feedback forced-feedback">{this.props.validFeedback}</div> : null
            }
            {
                this.props.isInvalid && this.props.invalidFeedback ?
                    <div className="invalid-feedback forced-feedback">{this.props.invalidFeedback}</div> : null
            }

        </>
    }
/* CSS */
.valid-feedback,.invalid-feedback {
  &.forced-feedback {
    display: block;
  }
}

I am not using bare Bootstrap 4 but this work in my environment as it does with usual .form-controls

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
H-a-w-kcommented, Feb 6, 2020

You can add className={classNames(isInvalid && “is-invalid”)} to your Typeahead

1reaction
karlderkaefercommented, Apr 11, 2021

from stackoverflow you can add classes like like this

<Button {...(condition ? {bsStyle: 'success'} : {})} />

check my example sandbox with typeahead and formik

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation · Bootstrap v5.0
When attempting to submit, you'll see the :invalid and :valid styles applied to your form controls. Custom feedback styles apply custom colors, borders, ......
Read more >
Force to show invalid-feedback in Bootstrap 4 - Stack Overflow
Is there an easy and simple way to show invalid-feedback by adding Bootstrap related CSS classes? I found one solution: <div class="invalid- ...
Read more >
Bootstrap 5 Form Validation - W3Schools
The input fields will have a green (valid) or red (invalid) border to indicate what's missing in the form. You can also add...
Read more >
Bootstrap display invalid-feedback server side validation
I worked on a Bootstrap v4.4 form where the validation is done on the server-side (Laravel) and when I receive errors on the...
Read more >
Validation · Boosted v5.0
When attempting to submit, you'll see the :invalid and :valid styles applied to your form controls. Custom feedback styles apply custom colors, borders, ......
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