Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

javascript - Pipedrive webforms not loading inside react bootstrap modal

I have a pipedrive form that needs to be render inside the react bootstrap modal. But it simply does not load the form. Its totally empty.

<Modal size="xl" show={this.state.isOpen} onHide={this.closeModal} dialogClassName="contact-modal modal-xl">
      <Modal.Header closeButton>
        <Modal.Title>Contact Us</Modal.Title>
      </Modal.Header>
      <Modal.Body className="px-0">
        {
          this.state.isOpen &&
          <div className="pipedriveWebForms text-center" data-pd-webforms="https://webforms.pipedrive.com/f/33bqHAoXSWM37q2MD4RrpBN4sx7TNeZ7SfED403dZ90EBjtERc2JOptKx7juMQQrV">
                    <script src="https://webforms.pipedrive.com/f/loader" defer></script>
                </div>
            }
             
      </Modal.Body>
    </Modal>

Here is the sandbox, https://codesandbox.io/s/amazing-albattani-lbth3?fontsize=14&hidenavigation=1&theme=dark

I tried keeping the script inside the componentdidmount, componentwillmount and inside the head tag. but it does not work. While keeping it outside the modal, the form works. I have been trying to find out why its not working inside the react bootstrap modal.

I am just a beginner working with react and its been a hard time trying to find a solution.

question from:https://stackoverflow.com/questions/65949160/pipedrive-webforms-not-loading-inside-react-bootstrap-modal

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem was when your modal is closed, the div with class pipedriveWebForms is not rendered. To fix it you need to load the JavaScript every time you open the modal.

This is what I did:

  openModal = () => {
    this.setState({ isOpen: true });
    const script = document.createElement("script");
    script.src = "https://webforms.pipedrive.com/f/loader";
    script.defer = true;
    document.body.appendChild(script);
    this.setState({ pDriveScript: script });
  };
  closeModal = () => {
    this.setState({ isOpen: false });
    document.body.removeChild(this.state.pDriveScript);
  };

Or just use the embed tag.

      <embed src="https://webforms.pipedrive.com/f/33bqHAoXSWM37q2MD4RrpBN4sx7TNeZ7SfED403dZ90EBjtERc2JOptKx7juMQQrV"/ >

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...