Availity / availity-reactstrap-validation

Easy to use React validation components compatible for reactstrap.
https://availity.github.io/availity-reactstrap-validation/
MIT License
191 stars 70 forks source link

Question: onChange on AvRadioGroup fires twice #187

Closed diegodesouza closed 3 years ago

diegodesouza commented 4 years ago

Hi quick question,

I'm wondering if there's a way to stop the AvRadioGroup onChange from firing twice?

  onSelectInquiryType = (event) => {
    event.persist();
    event.preventDefault(); // tried this
    event.stopPropagation() // tried this
    const {value} = event.target;
    const {store} = this.props;

    store.onSelectedInquiryType(value);
  };
            <AvRadioGroup
              className="mt-3"
              name="InquiryType"
              required
              onChange={this.onSelectInquiryType}
            >
              <AvRadio label="Claims" value="Claims"/>
              <AvRadio label="Medical Records" value="Medical Records"/>
              <AvRadio label="General Inquiry" value="General Inquiry"/>
            </AvRadioGroup>
diegodesouza commented 4 years ago

Seems like Availity-React RadioGroup onChange only fires once, but Wouldn't want to rewrite the whole form because of this.

GoPro16 commented 4 years ago

You can check for undefined and if so ignore the value for the time being. At least that is how we have handled it as a work around.

diegodesouza commented 4 years ago

@GoPro16 do you meant check the event for undefined? EDIT: I mean, what part of the event rather, should i be checking?

GoPro16 commented 4 years ago

One of the onChange callbacks with have event.target as null and the other will not.

diegodesouza commented 4 years ago

So to understand this better, sorry for lingering on this.

 onSelectInquiryType = (event) => {
    event.persist();

    if (event.target) {
      const {store} = this.props;
      store.onSelectedInquiryType(event.target.value);
    }
  };
diegodesouza commented 4 years ago

The above still calls the onChange a couple of times =/

diegodesouza commented 3 years ago

Doesn't seem to be an issue any longer