react-dropzone opens files chooser twice - javascript

I an encountering an issue with react-dropzone for quite a long time.
First, let's jump straight to the problem with a video: https://drive.google.com/open?id=1UmWtHbQ9U0LBHxYtZ1YSoXrfsezwH-os
The file choser window opens twice on every file inputs of my website, it is not an infinite loop, just twice.
Here is the code I use for this dropzone:
<Dropzone onDrop={this.onDrop.bind(this)}
key={this.state.key}
style={{border: "none"}}>
<div className="input-file">
<label for="file">
<button type="button">Choisissez un fichier</button>
</label>
</div>
<div className={"file-name " + (!this.state.selectedOption ? '' : 'hidden')}>
Aucun fichier choisi
</div>
<div className={"file-name " + (this.state.selectedOption ? '' : 'hidden')}>
{this.state.selectedOption}
</div>
</Dropzone>
The unwanted event happens every time I drop or even when I click on the input itself
If hope to give you guys enough information, if you need more I will more than happy to share code.

Just stumbled upon this too, in my case this was related to Dropzone being wrapped in a label. label passes clicks to descendant inputs.
As a workaround, you can remove the parent label (or change it to div or whatever).
Or, although I do not recommend it, monkey-patch Dropzone.prototype.onInputElementClick (or subclass and override). No further instructions here, as to not facilitate people shooting their feet.
Related react-dropzone issue: https://github.com/react-dropzone/react-dropzone/issues/182.

Faced the same issue, later found a way to solve it. Just add stopPropagation to parent div onClick.

This issue has been resolved in react-dropzone version 10.1.3.
I had the problem with version 10.1.0. Once I upgraded it to v10.1.3 in package.json, the problem is gone.
"dependencies": {
"react-dropzone": "^10.1.3"
}

Related

JavaScript class removing doesn't apply transition

Hey I have this problem that when I'm removing class dynamically it doesn't apply transition. Don't worry problem isn't with class itself, because when I try to delete manually trough dev tools it applies transition.
Here is the situation. I have big popup but lets just write it like this.
<div class="popup hidden">
<div class="popup__content hidden">
Bunch of stuff here that doesn't really matter
</div>
</div>
I am generating this markup into its container with insertAdjacentHTML. I have removeHidden method that looks like this
removeHidden(arr) {
[...arr].forEach(el => el.classList.remove('hidden'));
}
And I'm calling this method with passing a html collection as an argument, in this case those are both of the divs that have a hidden class.
removeHidden(document.getElementsByClassName('hidden'));
Now everything works fine, I mean classes are removed, my popup is shown, except that I don't get that nice transition I built into these classes, which works fine when deleting automatically which I already said just to note You that that is not a problem.
Thanking you all in advance for solving this problem! ;)
Problem solved. I just added timer where after 0.2 seconds those classes are removed.

React Bootstrap button looking faded

I used the
<Button bsStyle="primary" bsSize="large">Primary</Button>
Unlike the question here React-bootstrap button bsStyle , I have included the bootstrap css in the root html page.
I am unable to figure the issue.
Here is my code
Index.ejs
Css file :
Component.jsx:
import {Button, Col, Glyphicon, Label, OverlayTrigger, Row, Table, Tooltip} from "react-bootstrap";
<Button href={version.downloadUri} bsStyle="primary" bsSize="large">
Primary button
Main issue:
I do see the button and I also think that the css is being applied cause when I hover over the button, it looks normal. The button on the other hand in its natural state looks faded.
Herewith attaching screenshot of button. It is behaving as normal as it gets. Probably you are messing something in css. However I used react-bootstrap and here what I got:
Could you post your button's screenshot ?
I happened to finally figure out the issue today when I had the time today. It is a bit tough to accept but the href attribute is what caused the css to not be applied.
This surely was strange considering the fact that it is a prop that is officially supported and mentioned in the react-bootstrap docs here https://react-bootstrap.github.io/components.html#buttons-props . On looking deeper at the code that's finally the output using inspect element in chrome, it turns out that the href caused the component to be rendered as an anchor tag. So basically the css was being applied but to an anchor tag. This was the main issue. Hence I just wrapped the anchor tag around the button and now it works perfectly. I still don't know what the actual cause was. I created a small snippet of something similar on jsfiddle here http://jsfiddle.net/zrue0aa1/21/ and it works.
In case anyone else faces this issue , my final code for the button is this:
<a href={version.downloadUri}>
<Button className="primary" bsStyle="primary" bsSize="large"
disabled={version.version === null}>
<span>Download
</span><br/>
<span>
Version : {version.version === null ? "Null" : version.version}
</span>
</Button>
</a>

Angular with ng-flow : existing flow object

Might be a silly question but I couldn't figure the solution out myself or google it. I'm using a button for click+upload files. However, I also want to add the drag+drop functionality the same time - using preferably the same flow object and function. Here's my current code:
<div flow-init flow-name="uploader.flow" flow-files-submitted="uploadFiles()"
flow-file-success="fileUploaded()">
<label for="file-upload" class="upload">Files</label>
<input id="file-upload" type="file" flow-btn>
So I'd like to use the 'uploader.flow' scope for my drag and drop too executing 'uploadFiles()' with it on submit. Here's what I've been trying:
<div flow-init flow-object="...??..." flow-drop
flow-files-submitted="uploadFiles()" flow-file-success="fileUploaded()" ></div>
I believe myself the issue is only that I can't figure out what to put in flow-object. But I doubt it was that simple. Might be something also with the new init? Should it be done or not.
Another way around of course could be to find the first shared parent element and init it there instead for both the same time? But would this be a bit too vague?
So in the end I did what I didn't originally want to do. I went up the parent elements until I found a common one the both were children of and did the initialization for ng-flow there instead.
It works.

Using jQuery to remove html elements from a dropdown

<script>
$(document).ready(function() {
$('.notification .tools .remove').on('click', function () {
alert('hola');
$(this).parentsUntil('.notification').remove();
});
});
</script>
<div id="notification-list" class="notification-chain" style="display:none">
#foreach ($notifications as $notification)
<div class="notification" style="width:300px">
<div class="tools">
</div>
<div class="notification-messages">
<div class="message-wrapper">
<div class="heading">{{ $notification->name }}</div>
<div class="description">{{ 'User ' .$notification->points_to. ' ' .$notification->content }}</div>
<div class="date pull-left">{{ $notification->created_at }}</div>
</div>
<div class="clearfix"></div>
</div>
</div>
#endforeach
</div>
Hello readers,
Above is currently what I'm working with. It displays a drop-down to hold all notifications a user has received and I currently have an x in the top corner of each "notification" div.
However none of the above jQuery seems to be running. The alert won't display and I get nothing in the console.
Please feel free to ridicule me and tell me what stupid thing I'm doing wrong.
Many thanks.
I appreciate all the help guys.
Here are some laravel.io files with some wider context:
The full html:
http://laravel.io/bin/Nk4xP
js for the dropdown:
http://laravel.io/bin/9vn1O#
Here are some debugging tips:
Think about all the things that might be going wrong, then start ruling them out. For example:
Maybe jQuery is not loaded at all.
Maybe the selector for the event handler is incorrect and jQuery can't find an element to attach the event handler to.
Maybe the code in your $(document).ready() function is not executing, and the event handler is never set up.
Using a combination of changes to your code and the browser console, you can rule these three things out:
Is jQuery loaded? Open the console & type $ - if it says undefined, then that's your problem.
Is the selector for the element incorrect? Open the console and type $('.notification .tools .remove'). If you get an empty array, then that's your problem. As an added bonus, Chrome (and probably other browsers) will highlight the selected element if you mouse over it - this is useful in case you're selecting a different element than you expected.
Is the $(document).ready() code executing? Stick a different alert in there at the top of the function & see if it fires when you reload the page.
It's important to tackle issues like these one at a time - what happens if you change two or more things at once, and the problem goes away (or a new problem arises)? You won't know which one solved or caused the problem!
I was able to make it work in the fiddle below.
I removed the display:none (so I can see the div) and the non html characters. Try looking at the browser console (F12 in linux and windows computers) and see if there are errors. Javascript errors will prevent further code to run.
Also I put a text within the a href tag
remove
https://jsfiddle.net/m9rktusb/
As notification is a class for the div, there should be a dot in front of the class as a selector like this:
$(this).parentsUntil('.notification').remove();
Hope this works.
Luke can you please show us the final HTML?
the code is running perfectly, so the issue should be somewhere else.
https://jsfiddle.net/z7958hx7/1/
$(document).ready(function() {
$('.notification .tools .remove').on('click', function() {
alert('hola');
$(this).parentsUntil('.notification').remove();
});
});

HTML input fields does not get focus when clicked

I have a problem and I can't figure out what exactly is causing this behavior. I cannot access my input fields and textareas on my HTML form.
Unfortunately, the JS, HTML and CSS are very large, so I can't really post it all here.
Can anybody tell me what to look for when debugging this strange behavior?
UPDATE
If I move the cursor over the input field I can see the text cursor, but when I click it the field does not get the focus. I can access the field via pressing the Tab key and if I right click on it and then click on the field I also get the focus for it.
...and nope, they don't have the disabled or readonly attributes ;-)
when i click it the field does not get the focus. i can access the field via pressing the "tab-key"
It sounds like you've cancelled the default action for the mousedown event. Search through your HTML and JS for onmousedown handlers and look for a line that reads.
return false;
This line may be stopping you from focusing by clicking.
Re: your comment, I'm assuming you can't edit the code that adds this handler? If you can, the simplest solution is to just remove the return false; statement.
is there a way to just add functionality to the event-trigger by not overwriting it?
That depends on how the handler is attached. If it's attached using the traditional registration method, e.g. element.onmousedown, then you could create a wrapper for it:
var oldFunc = element.onmousedown;
element.onmousedown = function (evt) {
oldFunc.call(this, evt || window.event);
}
Since this "wrapper" doesn't return false, it will not cancel the default action (focusing) for the element. If your event is attached using an advanced registration method, such as addEventListener or attachEvent then you could only remove the event handler using the function name/reference and reattach it with a wrapped function similar to the above. If it's an anonymous function that's added and you can't get a reference to it, then the only solution would be to attach another event handler and focus the element manually using the element.focus() method.
I had this problem too. I used the disableSelection() method of jQuery UI on a parent DIV which contained my input fields. In Chrome the input fields were not affected but in Firefox the inputs (and textareas as well) did not get focused on clicking. The strange thing here was, that the click event on these inputs worked.
The solution was to remove the disableSelection() method for the parent DIV.
Use the onclick="this.select()" attribute for the input tag.
I know this is a very old thread, but this just happened to me recently; took me a while to figure it out.
This same issue can be caused by putting 'input' elements inside of pair of 'label' tags.
In my case, I had intended to create a pair of 'div' tags but instead I accidently created a pair of 'label' tags, then inserted some text input fields 'input type="text"..' using DOM.
It displayed normally on the screen, but when I clicked on any of the text fields, the cursor kept jumping back to the first 'input' and really acting erratic.
Took me a while to figure this out because this behavior is subtle, and not at all what I would have expected from making this kind of mistake.
bsnider
I've been struggling with the same problem a while ago. I was using the jquery.layout plugin in a modal jquery-ui dialog and I couldn't access any of the fields in it.
It appeared to be a z-index problem (some div was over my input fields, so I couldn't click them). You should check it out and try changing the z-index value of your input fields.
This happens sometimes when there are unbalanced <label> tags in the form.
I had this problem too, and in my case I found that the color of the font was the same color of the background, so it looked like nothing happened.
I have read all the answers above, and some directed me to the problem, but not to the solution for the problem.
The root cause of the problem is disableSelection(). It is causing all the problems, but removing it is not a solution, as (at least in 2016 or slightly before), on touch-screen devices, you "have" to use this if you want to be able to move objects with jQuery.
The solution was to leave the disableSelection() to the sortable element, but also add a binding action just above:
$('#your_selector_id form').bind('mousedown.ui-disableSelection selectstart.ui-disableSelection', function(event) {
event.stopImmediatePropagation();
})
The form in the jQuery element is just to stop propagation on the form, as you might need propagation on some elements.
This can occur in bootstrap if you do not place your columns inside a <div class ='row'>. The column floats are not cleared and you could get the next column overlying the previous, hence clicks wont hit the dom elements where you expect.
If you are faced this problem while using canvas with DOM on mobile devices, the answer of Ashwin G worked for me perfectly, but I did it through javascript
var element = document.getElementById("myinputfield");
element.onclick = element.select();
After, everything worked flawlessly.
I had the similar issue - could not figure out what was the reason, but I fixed it using following code. Somehow it could not focus only the blank inputs:
$('input').click(function () {
var val = $(this).val();
if (val == "") {
this.select();
}
});
For Anyone Using Electron
For anyone having this issue with Electron specifically, the problem for me was using alert before selecting the input fields. Apparently alert and confirm aren't entirely supported by Electron, and therefore can mess up input fields. If you'd still like to use them, refer to this post: https://stackoverflow.com/a/38859135/12293837
I had this problem because of this code:
$("#table tbody tr td:first-child").bind("mousedown", function(e){
e.preventDefault();
$(this).parents('tr').removeClass('draggable');
});
I resolved it by removing
e.preventDefault();
New code:
$("#table tbody tr td:first-child").bind("mousedown", function(){
$(this).parents('tr').removeClass('draggable');
});
Just in case someone else is looking for this answer, we had a similar problem and solved it by changing the z-index of the input tags. Apparently some other divs had extended too far and were overlapping the input boxes.
I had this problem for over 6 months, it may be the same issue. Main symptom is that you can't move the cursor or select text in text inputs, only the arrow keys allow you to move around in the input field. Very annoying problem, especially for textarea input fields. I have this html that gets populated with 1 out of 100s of forms via Javascript:
<div class="dialog" id="alert" draggable="true">
<div id="head" class="dialog_head">
<img id='icon' src='images/icon.png' height=20 width=20><img id='icon_name' src='images/icon_name.png' height=15><img id='alert_close_button' class='close_button' src='images/close.png'>
</div>
<div id="type" class="type"></div>
<div class='scroll_div'>
<div id="spinner" class="spinner"></div>
<div id="msg" class="msg"></div>
<div id="form" class="form"></div>
</div>
</div>
Apparently 6 months ago I had tried to make the popup draggable and failed, breaking text inputs at the same time. Once I removed draggable="true" it works again!
I'm using JQuery UI and Bootstrap so I faced this issue and I think it is a conflict between the two as in normal case the textarea or the input filed is editable by nature but I made this solution after testing all the above answers but none solve the cross browser support for all major browsers, but I solved it and I like to share my solution you can use it on input text and textarea
(Tested on Desktop: IE (All Versions), Chrome, Safari, Windows Edge, Firefox, Visual Studio Cordova Ripple Viewer on Windows & Visual Studio Cordova Windows 10 Store App)
(Tested on Mobile: Chrome, Firefox, Android Internet Browser & Visual Studio Cordova App on Android & Visual Studio Cordova Windows 8 + 8.1 + 10 Phone App)
This is the HTML Code:
<textarea contenteditable id="textarea"></textarea>
This is The CSS Code:
textarea {
-webkit-user-select: text !important;
-khtml-user-select: text !important;
-moz-user-select: text !important;
-ms-user-select: text !important;
user-select: text !important;
/*to make sure that background color and text color is not the same (from the answers above)*/
background-color:#fff !important;
color:#733E27 !important;
}
This Is The JQuery Code On Document Ready
$("textarea").click(function() {
setTimeout(function(){
$("textarea").focus();
//add this if you are using JQuery UI (From The Solutions Above)
$("textarea").enableSelection();
var val = $("textarea").val();
if (val.charAt(val.length-1) !== " " && val.length !== 1) {
alert(val.length);
val += " ";
}
$("textarea").val(val);
}, 0);
});
if (navigator.userAgent.indexOf('Safari') !== -1 || navigator.userAgent.indexOf('Chrome') !== -1) {
//alert('Its Safari or chrome');
$("textarea").onfocus(function(e) {
setTimeout(function(){
var end;
if ($("textarea").val === "") {
end = 0;
} else {
end = $("textarea").val.length;
}
if ($("textarea").setSelectionRange) {
var range = document.getElementById('textarea').createTextRange();
if (range) {
setTimeout(range, 0, [end, end]);
} else { // IE style
var aRange = document.getElementById('textarea').createTextRange();
aRange.collapse(true);
aRange.moveEnd('character', end);
aRange.moveStart('character', end);
aRange.select();
}
}
e.preventDefault();
return false;
}, 0);
});
}
You can test it on my web application at www.gahwehsada.com
When you say
and nope, they don't have attributes: disabled="disabled" or readonly ;-)
Is this through viewing your html, the source code of the page, or the DOM?
If you inspect the DOM with Chrome or Firefox, then you will be able to see any attributes added to the input fields through javasript, or even an overlaying div
I just found another possible reason for this issue, some input textboxes were missing the closing "/", so i had <input ...> when the correct form is <input ... />. That fixed it for me.
In my case it was Bootstrap popup in opened state.
Text input was in another calendar popup on top of Bootstrap one, input got its focus back after removing tabindex="-1" attribute from Bootstrap modal.
iPhone6 chrome
Problem for me was placing the input field inside <label> and <p>
like this :
<label>
<p>
<input/>
</p>
</label>
I changed them to
<div>
<div>
<input/>
</div>
</div>
And it works for me .
After check this answer, Please check other answers in this page, this issue may have different reasons
Its worth adding that having the property pointer-events:none on your input label will also produce this unwanted behaviour.
It might be because of invalid for attribute in the label attribute
<input type="text" id="your_name" name="your_name">
<label for="your_name">Your Name</label>
<input type="text" id="your_email" name="your_name">
<label for="your_name">Your Name</label>
I have tried to update the for attribute in the second label to your_email instead of your_name and its works for me
<label for="your_email">Your Name</label>
This will also happen anytime a div ends up positioned over controls in another div; like using bootstrap for layout, and having a "col-lg-4" followed by a "col-lg=8" misspelling... the right orphaned/misnamed div covers the left, and captures the mouse events. Easy to blow by that misspelling, - and = next to each other on keyboard. So, pays to examine with inspector and look for 'surprises' to uncover these wild divs.
Is there an unseen window covering the controls and blocking events, and how can that happen? Turns out, fatfingering = for - with bootstrap classnames is one way...
I had the same problem. I eventually figured it out by inspecting the element and the element I thought I had selected was different element. When I did that I found there was a hidden element that had z-index of 9999, once I fixed that my problem went away.
the problem for me was that I was using class="modal fade", I changed it for class="modal hide". That solved the issue.
I had the same problem. Tore my hair for hours trying all sorts of solutions. Turned out to be an unclosed a tag.Try validate your HTML code, solution could be an unclosed tag causing issues
I had this issue using Bootstrap + contact form 7.
I for some reason I put the label as the container of the form and that was the issue for not being selectable on mobile.
<label>
<contact form>...</contact form>
</label>
Seemed to break all inputs except the first input and the submit.
I had the same issue and the fix was to remove the placeholders and I changed the design of the form to use labels instead of placeholders...
I had this issue caused by a sort of overlap of a div element with a bootstrap class ="row" over a "brother" div element with the class="col", the first hid the focus of the second div element.
I solved taking outer the div row element from that level of the divs' tree and so rebalancing bootstrap logical hierarchy based on the row and col classes.
I had this same issue just now in React.
I figured out that in the Router, Route. We cannot do this as it causes this issue of closing the mobile keyboard.
<Route
path = "some-path"
component = {props => <MyComponent />}
/>
Make sure and use the render instead in this situation
<Route
path = "some-path"
render = {props => <MyComponent />}
/>
Hope this helps someone
Daniel

Categories