It is not possible to submit a form within a Modal using React Semantic UI

I am working on creating a modal for submitting a form using React semantic UI. However, I am encountering an issue with the submit button not functioning correctly and the answers not being submitted to Google Form even though I have included action={GOOGLE Form URL}. Below is a snippet of the code and I am hoping someone can help identify the problem. The click event on the button seems to work as it logs something when console.log() is added.

const GOOGLE_FORM_ENDPOINT = "http~~~"

return (
  <Modal open={isModalOpen} as={Form}>
    <Modal.Header>
      この製品の改善のためにアンケート調査のご協力をお願いします。
    </Modal.Header>
    {/* <Header
      icon="pencil"
      content="この製品の改善のためにアンケート調査のご協力をお願いします。"
      as="h2"
    /> */}
    <Modal.Content>
      <Form action={GOOGLE_FORM_ENDPOINT}>
        <Form.Field>
          <label htmlFor="game">他にプレイしたいゲームはありますか?</label>
          <input
            id="game"
            name="entry.1294001289"
            placeholder="ポーカー、人狼、人生ゲーム・・・"
            required
          ></input>
        </Form.Field>
        <Form.Field>
          <label htmlFor="price">
            今遊んだゲームに買い切りでいくら払いますか?(10円単位でお願いします。)
          </label>
          <input
            id="price"
            type="number"
            name="entry.1184266257"
            placeholder="5000"
            min="0"
            step="10"
            required
          />
        </Form.Field>
        <Form.Field>
          <label htmlFor="request">
            その他、何かご要望やご意見があればお願いします。
          </label>
          <textarea id="request" name="entry.656434793"></textarea>
        </Form.Field>
        <Form.Button
          content="submit"
          onClick={(e) => {
            e.preventDefault()
            setIsModalOpen(false)
            app?.endGameRequest()
          }}
        ></Form.Button>
      </Form>
    </Modal.Content>
  </Modal>
)

 

Answer №1

When you invoke e.preventDefault(), you are stopping the browser from carrying out its default action, which is to submit the form.

You have two choices when it comes to submitting the form:

  1. Remove e.preventDefault() and allow the browser to handle the submission as usual. The downside of this approach is that the user will be redirected to the action URL, which may not provide the best experience. This brings us to the second option.
  2. Use e.preventDefault() to prevent the form from being submitted traditionally, but instead use ajax to submit the form - for example, with fetch.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue: The variable 'HelloWorld' has been declared but not utilized

Why am I encountering an error when using TypeScript, Composition API, and Pug templating together in Vue 3? How do I resolve this issue when importing a component with the Composition API and using it in a Pug template? ...

Database-driven Dynamic Dropdown

I'm currently working on a project where I need to retrieve a list of names from my database for the Select component. However, I'm facing difficulties in writing the appropriate functions required for this task. The dropdown renders successfully ...

In Nodejs, the value of req.headers['authorization'] is not defined when using JWT (JSON Web Token)

Below is the implementation of JWT in Node.js: const express = require("express"); const jwt = require("jsonwebtoken"); const app = express(); app.use(express.json()); const user = [ { name: "Rohan", id: 1, }, { name: "Sophie", id ...

What is preventing images from displaying in my slider within baguetteBox?

Currently, I am in the process of incorporating a slider into my website using the baguetteBox library. After consulting the documentation, I successfully implemented an example that is functioning smoothly without any issues. In order to display a series ...

Extracting a nested property from a JSON object without relying on the lodash get method

We have a sample json data: { "name": "app", "version": "0.1.0", "description": "Sample description", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "so ...

Tips on customizing a Drawer with Material-UI v5

When working with Material-UI v4, you could style the Drawer component like this: <Drawer variant="persistent" classes={{paper: myClassNameHere}} > The myClassNameHere is generated by using useStyles, which in turn is created using mak ...

Caution in material-ui version 4.0.1: Please ensure you have an element capable of holding a ref

After upgrading to material-ui v4.0.1, I noticed that Modals now require a forwarded ref, which has caused some issues for me when trying to implement a solution using class components and Dialogs. I attempted to use React.createRef() and React.forwardRef ...

Scrolling automatically to the first empty mandatory field with the help of AngularJS

After utilizing angular js to create a form with 7 input elements, I encountered an issue. Upon clicking submit, the form should scroll up to the first blank required field. However, it is not accurately identifying the left blank field. Any suggestions on ...

Please indicate the generator title (for example, nx generate @nrwl/workspace:library) specifically for Angular

Currently, I am expanding my knowledge in web development. While working with Angular, I encountered an issue when trying to create a new component. The error message reads "Specify the generator name (e.g., nx generate @nrwl/workspace:library)" after exec ...

The alignment of the text next to the icons is not correct

Is it necessary to use flexbox, or is there an easier way to achieve the same result? It has been a while since I last practiced and I can't seem to remember much. .sadaka-contacts p { color: #115c9b ...

Tips for adding a button to the SB Admin 2 Card header without altering its height

I am currently utilizing the SB Admin 2 template for my project and encountering difficulty when trying to add a button in the card header without altering the default height. The goal is to maintain a consistent look across both cards, as illustrated in t ...

Styling with CSS: Utilizing the Float Left Property to Anchor Elements

Currently, I have implemented an anchor element that utilizes a CSS class to replace the text with an image. Despite its unusual nature, the end result is mostly satisfactory. .toolLink a { overflow:hidden; } .toolEdit { float:left; ba ...

Retrieving POST request headers in Nightmare JS following a click() function execution and a wait() function delay

When I navigate a page, I input something in a field using type(), click on a button with click(), and then wait for an element to appear using wait(). I am interested in retrieving all the headers associated with the POST request that is triggered after ...

Controlling the window opener; Inserting text into an element in the parent window

A pop-up window allows users to select files, then displays the selected image's URL. However, I need to take additional steps beyond that. I am seeking a method to input the URL into an input element on the parent window. window.opener.document.wri ...

Are toggle functionalities triggered when an element is clicked?

How come the span triggers functions a and b when first clicked, is there a way to set it up so that it calls function a on the first click and then function b on the second click? function a(id) { $.post("url.php", {'id':id}, function() { ...

Optimize your mobile experience by creating a notification menu that is scrollable and fixed in position

Recently, I purchased Moltran, but encountered a major issue: The notification menu disappears on mobile devices, which is not ideal for me. After some research, I discovered that removing the hidden-xs class from the li notification element can solve this ...

I encountered an issue while generating a crypto address on the Waves blockchain using the @waves/waves-crypto library in TypeScript

Encountering an issue with finding "crypto-js" in "@waves/waves-crypto". Despite attempts to uninstall and reinstall the module via npm and importing it using "*wavesCrypto", the error persists within the module's index.d.ts file. I am attempting to ...

The error message 'ReferenceError client is not defined' is indicating that the

I'm currently attempting to retrieve the id of clients connecting to my socket.io/node.js server by following the method outlined in the top response on how to get session id of socket.io client in Client. However, I am encountering an error message: ...

Using Array.push within a promise chain can produce unexpected results

I have developed a method that is supposed to retrieve a list of devices connected to the network that the client has access to. export const connectedDevicesCore = (vpnId: string, vpnAuthToken: string) => Service.listVPNConnectionsCore ...

Pressing the enter key within Material UI Autocomplete will allow you to quickly create new

Wouldn't it be great if Autocomplete in material ui could do this: wertarbyte Imagine being able to insert text (string) without the need for a list of elements to select from. This means that the noOptions message shouldn't appear, and instead ...