After clicking the add button, I would like to close the modal window

I am having trouble closing the modal after clicking the add button. The form in the modal is used for uploading data to a database. The upload function works correctly, but I'm unsure how to close the modal upon clicking the add button. I am currently using daisyUI.

Here is the code snippet:

<label htmlFor="add-doc" className="btn btn-sm btn-success ml-auto mb-3">
        Add Document
      </label>
      <input type="checkbox" id="add-doc" className="modal-toggle" />
      <div className="modal">
        <div className="modal-box">
          <h3 className="font-bold text-lg mb-5">Add Document</h3>
          <div className="form-control">
            <label className="input-group mb-5">
              <span>Document Name</span>
              <input
                type="text"
                placeholder="document name"
                className="input input-bordered"
                name="docName"
                onChange={fieldHandler}
              />
            </label>
            <label className="input-group mb-3">
              <span>Document Location</span>
              <input
                type="text"
                placeholder="document location"
                className="input input-bordered"
                name="docLoc"
                onChange={fieldHandler}
              />
            </label>
            <label className="label">
              <span className="label-text">Insert photo of document location</span>
            </label>

            <input
              type="file"
              className="file-input w-full max-w-xs"
              name="photoLoc"
              // onChange={fieldHandler}
            />
          </div>
          <div className="modal-action">
            <label htmlFor="add-doc" className="btn">
              Cancel{" "}
            </label>

            <label
              onClick={handleDocSubmit.bind(this)}
              htmlFor="add-doc"
              className="btn btn-success"
            >
              <button>Add</button>
            </label>
          </div>
        </div>
      </div>

Answer №1

Ensuring your input elements are enclosed in a form tag is not only beneficial for semantics but also adds functionality. Additionally, wrapping the submit button in a label might be unnecessary. When sending data to a server, it's essential to utilize the POST HTTP request method.

<label htmlFor="add-doc" className="btn btn-sm btn-success ml-auto mb-3"> Add Document </label>
<input type="checkbox" id="add-doc" className="modal-toggle" />
<div className="modal">
    <form method="POST">
        <div className="modal-box">
            <h3 className="font-bold text-lg mb-5">Add Document</h3>
            <div className="form-control">
                <label className="input-group mb-5">
                    <span>Document Name</span>
                    <input
                        type="text"
                        placeholder="document name"
                        className="input input-bordered"
                        name="docName"
                        onChange="{fieldHandler}"
                    />
                </label>
                <label className="input-group mb-3">
                    <span>Document Location</span>
                    <input
                        type="text"
                        placeholder="document location"
                        className="input input-bordered"
                        name="locDoc"
                        onChange="{fieldHandler}"
                    />
                </label>
                <label className="label">
                    <span className="label-text">Insert photo of document location</span>
                </label>
                <input type="file" className="file-input w-full max-w-xs" name="photoLoc" //
                onChange={fieldHandler} />
            </div>
            <div className="modal-action">
                <label htmlFor="add-doc" className="btn"> Cancel{" "} </label>
                <label htmlFor="add-doc" className="btn btn-success">
                    <button onClick="{handleDocSubmit.bind(this)}">Add</button>
                </label>
            </div>
        </div>
    </form>
</div>

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

The implementation of a Like Button in Django using JS and DOM resulted in a 404 error

I am facing an issue with the 'live' like/unlike button functionality in Django and JavaScript DOM Upon clicking the button, an error is triggered POST http://127.0.0.1:8000/like/24 404 (Not Found) likePost @ javascripts.js:24 (anonymous) @ java ...

How can jQuery retrieve a string from a URL?

If I have a URL like http://www.mysite.com/index.php?=332, can jQuery be used to extract the string after ?=? I've searched on Google but only found information about Ajax and URL variables that hasn't been helpful. if (url.indexOf("?=") > 0) ...

Move object smoothly off screen without any delay

I have been experimenting with Animate.CSS and basic Jquery to add animations to elements coming on and off the screen. However, a problem I have encountered is that there is noticeable lag, especially when there is a background slideshow running simultane ...

What is the method for retrieving authorization response headers in a jQuery AJAX success callback?

While working on setting up encrypted username and password authorization on the front end, I encountered an issue where I am receiving a bearer authorization response header from the server. Interestingly, in Safari, I am able to retrieve this response he ...

Bringing a TypeScript module to life with a sprinkle of 'import

I am attempting to integrate the numbro JavaScript library into my TypeScript project. The numbro.d.ts file exports like this: declare const numbro: NumbroStatic; export default numbro; My simple import statement looks like this: import numbro from &apo ...

Full-Screen Popup Overlayaptic

Is it possible to create a popup that covers the entire browser window, including the search bar and other windows besides just the webpage area, for a very large interactive element? ...

How can I make sure my rows are properly aligned using the Grid

Looking at the image below, I am attempting to align "Ticket Number" and "Email" using a Grid: View My Result Image <Grid container direction="row" justifyContent="flex-start" alignItems="stretch" style={{ pad ...

Assigning values from an array to individual variables

I am facing a challenge with my form that allows users to upload multiple files. Specifically, I am struggling to extract the files from 'files[]' and assign their values to variables. This is my first time working on image uploads, and I would g ...

Challenge with Sequelize Many-to-Many Query

Currently, I am facing an issue with connecting to an existing MySQL database using Sequelize in Node. The database consists of a products table, a categories table, and a categories_products table. My goal is to fetch products, where each product includes ...

"Obtain a DOM element within an Angular directive by using the jQuery find method

When inspecting the DOM, I can see the element anchor tag present but cannot retrieve it using jquery.find(). The console returns a length of 0, preventing me from initializing angular xeditable on that element. angular.module('built.objects') ...

Tips for implementing xpath in module.exports with mocha javascript

Currently, I am utilizing mocha in conjunction with Node.js and have encountered a challenge. In my scenario, I need to use the XPath defined in one test file (verification.js) and apply it in another file (test.js). The issue arises from the fact that the ...

Establishing the properties of an object as it is being structured within a nested data format

I am in the process of creating a unique JSON representation, focusing on object composition to directly set key values during composition. However, I've encountered difficulty composing multiple objects in a nested manner. My goal is to find an expr ...

Passing a value from Javascript to PHP using Ajax in CakePHP 3.x results in an empty $_POST variable

Despite successfully alerting the post data with Ajax ({"booking":{"testdata":"testdata"}}), the issue arises when the PHP code fails to retrieve $_POST. Both JavaScript and PHP are present on the same page: Take a look at my code below: <script type ...

Revolutionize your rotation axis with Axis in three.js

Greetings! I am currently working with three.js and I am attempting to rotate my 3D model along the x-axis. However, when I use the following code: object.rotation.x += 0.01;, it does not produce the desired effect. The image below depicts the current ro ...

Combine year and month in 2 separate divs using the fullcalendar format: <div>Year</div> <div>Month</div>

Can someone help me with a coding issue I'm facing? I am trying to split the title of a calendar into two separate divs - one for the year at the top of the page and one for the month at the top of the calendar. I have tried using angular.element but ...

When executing JavaScript code with an Ajax HTTP request, the output displayed is 2 but the

I'm currently working on a local chat application and encountering an issue where it displays an undefined result before properly showing all data. Below is the code snippet: function chatDisplay(){ if(mainchat.msg.value== ""){ a ...

Safari (12.1) Webdriver abruptly crashes when using Selenium's click() function or actions.clickAndHold([specific web element]).perform()

While executing my selenium scripts, I encounter a severe crash specifically when running the Safari web browser and clicking certain links. The majority of click actions work fine with the Safari Webdriver. However, performing either webElement.click() o ...

How can I determine if the td I clicked on is in the first row or the last row, and how do I find out its row and column

I am working with a table that looks like the one in this link. https://i.sstatic.net/LCoLw.png Is there a way for me to determine if the td (input) I clicked on is in the first row or last row? Additionally, how can I figure out the column index and ro ...

Web page numerical data

Apologies if I'm repeating a question and I acknowledge that this is quite general. I am struggling to comprehend how to approach the following scenario: I aim to set a numerical value and enable the user to select checkboxes for different sides, wit ...

npm run is having trouble locating the graceful-fs module

I am currently enrolled in a course on DjangoRest and React. While I have experience with npm and Python, I have encountered an error that I am unable to resolve. Everything was going smoothly until I ran "npm run dev." package.json file { "name": "fron ...