Questions tagged [preventdefault]
Javascript event method to cancel the event if it is cancelable, without stopping further propagation of the event.
936
questions
0
votes
0
answers
37
views
Why is e.preventDefault() a function and not a property
Why was e.preventDefault() defined as a function and not as a property, for example e.preventDeafult = true;?
Wouldn't there even be advantages of it being a property, since you could set e....
0
votes
0
answers
17
views
How does React implement controlled text input?
If you are familiar with React, you might know that the <input/> element has an onChange handler, making the component controlled, and prevents changes to the input field unless the value field ...
0
votes
1
answer
39
views
Disable 'submit' button unless box is checked
Following on from a previous question I asked
Submit button not working with JS validation
I have been really struggling with getting the checkbox being checked to be part of the form validation.
my ...
0
votes
1
answer
23
views
link event.preventDefault doesn't work in a popup overlay window
I'm trying to prevent users to open directly unsafe links (http://).
here below is the code I'm using:
const container = document.querySelector('#container-id');
let links = container.queryselectorAll(...
0
votes
0
answers
7
views
Prevent submitting a form
I am making a DB of words. And before submitting a new word I want to check if entered word already exists in my DB. For that, I added e.preventDefault() but somehow it does not prevent the form and ...
0
votes
0
answers
17
views
How to force onWheel (SyntheticEvent, React) to be in an active mode?
WheelEvents are by default passive. Hence, event.preventDefault is not working. In my React project, I do want to prevent the default behavior, though.
When using event listeners, this can be solved ...
0
votes
1
answer
35
views
Prevent default on select focused
I am trying to prevent default on press F1 so it doesn't open a new tab to support.google.com, instead I want to use it as a hotkey for my app, this is working everywhere, except when I focus a select ...
0
votes
2
answers
23
views
I am get error jquery code bubbling method
I'm trying to make an application that includes input, paste and cut events. I have a problem. While paste, the input event also works. I want to close one. the code should not run twice. I applied ...
0
votes
1
answer
27
views
react app resets state and rerenders without e.preventDefault on click
I have a react app that seems to be resetting all of its state and re-renders the entire app when button is clicked:
the form + button:
<form>
...
<button
onClick={(e: React....
0
votes
1
answer
22
views
React - prevent calling useEffect for the first mount [duplicate]
I want to prevent calling my useEffect on the first mount.
how can I do this?
I want the best practice.
I don't want to use if condition
import { useState, useEffect } from "react";
const ...
0
votes
1
answer
9
views
How can I prevent angular @hostlistner directive from invoking a show menu display function every time outside clicked
I have a menu icon I want to toggle the display. It should show when the icon is click and hidden when any part of the window is clicked. But its always hidden and from my console log i can see @...
0
votes
0
answers
16
views
Form automatically submitting, why is preventDefault() not working
I recently created a link shortening application in react. I have a problem with the form automatically submitting when I enter a link, I have preventDefault() as you can see in the code and onSubmit ...
0
votes
2
answers
32
views
Preventing form from going to action page also prevents data from being submitted
I created a form that submits its input to a database via a PHP page, and it works great, except for that I can't get the below script to work.
The intention is to submit the form but without actually ...
0
votes
0
answers
45
views
Prevent going back in Drawer Navigator
I want to prevent user from leaving screen before saving details by clicking on any item in drawer menu. I used this below snippet to prevent navigation. But issue is I've screens which are hidden in ...
0
votes
1
answer
38
views
Prevent default on screen, but allow buttons to be pressed
I'm building a website in js/html/css. To play part of my game the user needs to press and hold the screen. This will default to highlighting the play area, so on click or touch events I want to use ...
0
votes
0
answers
31
views
Block PDF from Download from IDM
I have a PDF in my javascript project,and am attaching PDF from s3 in pdfjs_viewer and I want to block it from download through IDM, any solution ?
localhost:3000/pdf_page
0
votes
0
answers
17
views
How Do I make this function work so that the focus will be shifted to the next element in the index onClick?
Here I have re-directed the tab key to the arrowRight icon in my carousel (as the carousel keyboard navigation is completely broken) and now the tab functionality works well, however the focus does ...
1
vote
2
answers
84
views
How to use event.preventDefault() when function have arguments
i have a code like this:
const upListCandy = (candy) => {
/* How i add event.preventDefault() and it word*/
axios.post("example.com", {
candyName: candy.name
})...
0
votes
1
answer
123
views
How would i clear an EmailJS form after the user hits submit?
Currently if the user hits send, the only way to know if it worked is the button click animation, and would only know for sure if they inspected the page and saw the 'OK' message in console.
I'd like ...
0
votes
0
answers
86
views
How to create an event listener for the keyboard event 'ctrl + q' without it closing the browser window?
Problem summary: The eventListener for the 'keydown' event is supposed to perform a function when the 'ctrl' + 'q' keys are pressed simultaneously, similar to the keyboard shortcuts for search boxes ...
0
votes
0
answers
46
views
My function doesn't display the alert (preventDefault)
I am working on a to-do list app (React.js) and trying to make use of the preventDefault function. I've added an onSubmit attribute to my form element and want it to display an alert when the add ...
0
votes
1
answer
24
views
JS menu issue with preventDefault who close my menu
it is my first question on Stackoverflow after many years of reading answers here. Sorry for my english, it is not my nativelanguage.
I develop on wordpress a system to open and close the menu and ...
0
votes
5
answers
79
views
My preventDefault is not working when submit is pressed
I am currently working to learn different Javascript features. I am working with preventDefault. I was attempting to practice on the website I am making, but it is still refreshing the page. What am I ...
0
votes
1
answer
57
views
Best practices writing JavaScript that uses AJAX call to decide if default action should be prevented
I'm using JavaScript and jQuery to write a handler for my form being submitted. Based on certain conditions, the handler may allow or prevent the form from submitting.
This is straight forward but is ...
1
vote
1
answer
89
views
Can I use preventDefault to my event with passive equal true?
I've came across to the next article, there I found example with blocking scroll event:
document.body.addEventListener('pointermove', event => {
if (event.cancelable) {
event.preventDefault(...
0
votes
1
answer
53
views
Prevent user to click anywhere on page if changed value is not submitted
in my app, the user has multiple inputs, and I use @hostListener for click outside, because I have some complicated inputs (multiple checkboxes where I first need to check everything and after call ...
1
vote
1
answer
110
views
Why doesn't JavaScript event.preventDefault() work?
I have a JavaScript function for an anchor tag that has preventDefault() in it. However, it seems like the function only delays the default rather than prevent it.
The purpose of this function is to ...
-2
votes
1
answer
312
views
TypeError: Cannot read properties of undefined (reading 'preventDefault!!')
I keep getting the above below when I run this code
I don't see anything wrong with it and I don't know why its returning the above error. it use to work before, but after coming back to it today, it ...
0
votes
0
answers
12
views
How do I prevent react from reloading page when form is submitted [duplicate]
I can't figure out why event.preventDefault() isn't working in my chargeCardNow function.
The page is refreshing when the button in the form is clicked. Am I missing something obvious?
chargeCardNow ...
0
votes
1
answer
342
views
bootstrap 5 accordion: prevent toggle on specified elements in header
I have bootstrap 5 accordion
want to show popover to be displayed by clicking on icon in accordion header
popover is working but accordion is also toggling. I want to prevent toggling accordion if ...
0
votes
1
answer
145
views
I'm using React-Bootstrap. The e.preventDefault() is not working
I'm trying to put a simple Search Box in my navbar. I'm using React-Bootstrap, with python and django. So, I want to prevent default form behaivor: e.preventDefault();
The problem is: it is not ...
0
votes
2
answers
2k
views
Uncaught TypeError: Cannot read properties of undefined (reading 'preventDefault')
I trigger onchange attribute in input depending on a specific process. However, even if I "Event" as a parameter, I continue to get the error below. Also, alternatively, I tried Event....
0
votes
1
answer
104
views
Browser events default action - Is there a spec for it?
Some events has default action. For example - clicking on a checkbox will check/uncheck it. This can be prevented by the event.preventDefault() method.
While looking for the errorEvent default action, ...
1
vote
1
answer
453
views
Vue prevent form submit when pressing enter and using validation-observer
I have the following code:
<validation-observer v-slot="{ handleSubmit }" ref="formValidator">
<form @submit.prevent>
<!-- inputs -->
<button type=&...
1
vote
1
answer
32
views
How can I fix links that don't work in a minimized menu?
I have a pretty typical menu where the top items have children that fly out when you roll over. Works great above 992px. Below 992, you're supposed to click/tap the top item to get the flyout. That ...
0
votes
0
answers
58
views
jQuery return false from function
sorry for my english ...
I would like to advise how to stop a function from another function using e.preventDefault() or something else. I simplified the code for understanding. My code is here:
...
0
votes
1
answer
246
views
event.preventDefault( ) is NOT working in React
Unable to get values in console!
What am I doing it incorrectly?
Attached below is the functional component of React
The Handler Functions
import React, { useState, useRef } from 'react';
const ...
0
votes
1
answer
149
views
Custom prevent default in NodeJS
In JavaScript, when handling an event you can call event.preventDefault() which will prevent the default action of the event. In NodeJS this sets event.defaultPrevented to true. I want to be able to ...
3
votes
2
answers
875
views
react checkbox: event.preventDefault() breaks onChange function - why?
I have just found a stray event.preventDefault() that was breaking my checkboxes' onChange handler:
import { Component } from 'react';
class App extends Component {
constructor(props) {
super(...
-1
votes
1
answer
179
views
Javascript prevent Default
I want to have a read more button. I know that the problem in my code is that the e.preventDefault is only enabled for the readmore ID but I want it to be enable for the more_content ID.
$("#...
0
votes
0
answers
23
views
Javascript e.preventdefault only for one element?
Hi i want to add a "read more" and a "read less" button to my website. Works great for one element but the problem is that when I have more then one element both open and close ...
0
votes
0
answers
67
views
stop or allow closure of a modal window
I am very confused with this code. I try to allow the window to close if all the validations even the call by ajax are correct. The problem is that when I run preventDefault I can't cancel it anymore. ...
0
votes
0
answers
37
views
Plupload library: disable browse method problem
I'm using the plupload core API to create an audio upload system, without needing to upload anything from the computer because the data is recorded and uploaded through the APIs.
In order to disable ...
0
votes
1
answer
76
views
Is there a way of submitting this form after using the preventDefault function?
I am trying to check for selection in form, if selected option is cash, it submits else it calls an API and onse success response is returned the form should go ahead and submit
My Javascipt
document....
1
vote
0
answers
202
views
Vuetify - Why v-menu with open-on-hover is closing when mouse is over a list of v-select or v-combobox components
steps to reproduce:
1 - place a v-menu with open-on-hover property
2 - add a v-select or a v-combobox item to it..
when v-menu is opened, and the lists from v-select or v-combobox are displayed,
v-...
0
votes
1
answer
118
views
How to Submit Form and Bypass preventDefault
I'm trying to validate some field and display error messages when the required fields are not filled out. I use preventDefault to stop the form from submitting until the fields are filled out.
Can ...
1
vote
1
answer
92
views
JavaScript e.preventDefault(); does not work in form
Welcome to my question.
I am trying to make a sign up form that checks for some things.
I want to make an event listener on the submit button, to catch some things
First of all I have to prevent the ...
0
votes
3
answers
504
views
How to submit a form with 3 submit buttons using ajax without redirecting to the form action url in Laravel?
I have here a datatable with a form inside that has 3 submit buttons. I did a switch statement which it checks what submit button was clicked, then performs the operation of that submit button on my ...
0
votes
1
answer
18
views
PreventDefault() on $locationChangeStart stops every redirect and cannot be reverted
Target: Changing the URL without reloading the page because the URL is used for later functionalities but the relinks from other locations can't be changed easily.
Enviroment: ServiceNow instance (...
0
votes
0
answers
67
views
How to disable preventDefault( prevent save) and make it save in Javascript
I am new in Javascript and D365. My objective is : When adjustment type = Credit notes it will triggered the JS in adjustment invoice (adjustment amount >= invoice amount) alert will prompt, and ...