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.

How to access the errorMessage within an AvGroup?

See original GitHub issue

Hi,

I’m adding this library to my project, but can’t see how to access the errorMessage without using AvField ? (I don’t want to use AvField because I have a layout to preserve)

<AvGroup>
  <InputGroup size="sm">
    <InputGroupAddon addonType="prepend">
      <span className="input-group-text">&gt;100</span>
    </InputGroupAddon>
    <AvInput
      type="number"
      name="myNumber"
      value={numAvaility}
      validate={{
        min: {
          value: 100,
          errorMessage: "Must be over 100"
        }
      }}
      onChange={e => setNumAvaility(e.target.value)}
    />
    <AvFeedback>How do I get this message?</AvFeedback>
  </InputGroup>
</AvGroup>

Codesandbox here: https://codesandbox.io/s/broken-smoke-jpbgy

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
GoPro16commented, Jul 22, 2019

Alternatively @TheSharpieOne I was also thinking about making an update to allow the user to pass in a name prop on the AvFeedback and then rendering that field’s error message by default via the FormCtrl.getInputState like we do for AvField. You see anything wrong with this?

0reactions
matheusb-compcommented, Feb 15, 2020

but of course this.context wont work in functional components

@amillward You can access Legacy Contexts in a functional component: React docs

import PropTypes from 'prop-types';

function App(props, context) {
  const [numAvaility, setNumAvaility] = useState("0");
  const validation = (context.FormCtrl) ? context.FormCtrl.getInputState("numAvaility") : {};

  return (
    <AvForm>
      <Row>
        <Col xs={{ size: 5, offset: 3 }}>
          <AvGroup>
            <InputGroup size="sm">
              <InputGroupAddon addonType="prepend">
                <span className="input-group-text">&gt;100</span>
              </InputGroupAddon>
              <AvInput
                type="number"
                name="numAvaility"
                value={numAvaility}
                validate={{
                  min: {
                    value: 100,
                    errorMessage: "Must be over 100"
                  }
                }}
                onChange={e => setNumAvaility(e.target.value)}
              />
              <AvFeedback>{validation.errorMessage || ''}</AvFeedback>
            </InputGroup>
          </AvGroup>
        </Col>
      </Row>
    </AvForm>
  );
}

App.contextTypes = {
  FormCtrl: PropTypes.object.isRequired
}

export default App;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Need to through error message if a group has less ...
Select UI type as ALL. find_real_file.png. Select ALL instead of Desktop. Mark as correct and helpful if it solved your query. Regards,.
Read more >
Availity reactstrap Validation - AvForm
Pass an object in which the keys correspond to the name props of the form's input to set their initial value. Nested objects...
Read more >
Unable to send email to group. Getting an error message about
I tried to send an email to a group. I got an error message in red: "Please use the following format for email...
Read more >
Resolve Application Errors - Universal Service Administrative ...
Official, unexpired documents that prove their date of birth and SSN4 to resolve an error message about their identity. Consumers may submit a...
Read more >
I am not getting the error message in VScode without running it
Enable Your Squiggles to resolve this: click ctrl+shift+p; Search c/c++: enable error squiggles; click on it. It will enable your error ...
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