I'n using the select2 jQuery plugin with an ajax call to retrieve items for the dropdown list as the user types. Multiple selections (tags) are allowed and custom selections are allowed. When the dropdown list appears, if I use the cursor keys to go to the item I want and hit enter or tab, then the everything works fine. The select2-selecting callback is triggered and the input gets updated with the selection text.
If I click on an option with the mouse, however, the select2-selecting callback is not triggered and the input is not updated. The only thing that happens is that the dropdown menu disappears, nothing else.
I have another select2 input on the same page that allows only one selection and no custom selections. Clicking dropdown items in that works fine. Example on the plugin site similar to what I'm doing respond to clicks too, so it's not a general bug with the plugin.
I am aware that select2 actually has a hidden, completely translucent container div the size of the screen that is added to the DOM whenever a select2 input has focus. The select2 input sits on top of this 'underlay' and everything else is underneath it. When the select2 input looses focus, the 'underlay' disappears. I thought that the problem might be that the underlay had a higher z-index than the input, so when I click a dropdown item I'm actually just clicking the underlay and causing the input to loose focus. Well, the input (9999) does have a higher z-index than the underlay (9998). I just wanted to rule that out.
This bit of javascript was the culprit:
input.on("select2-blur", function() {
$(this).select2('close');
});
I think that at one stage the dropdown menu was only disappearing if I tabbed out of the input, but if I clicked outside of the input when the dropdown was visible, it stayed there. I had this is as a means to get rid of the dropdown when the input lost focus. It was the cause of the problem though. Strangely, even though I've removed it now, the dropdown disappears appropriately when I click outside the input, but I don't know why that is.
Related
I have a situation that happens in several of my components, where I show a new component, that is absolutely positioned and has an input control. I am using some basic logic to set the input control to set focus, which it does successfully.
When the control pops up, I can start typing right away as expected. However, if I click the "Tab" key, in this specific scenario, it navigates the underlying component to the next cell in the grid, instead of the top level div tab control.
However, If I click into the input box on this page with a mouse click, and then type, the tab key works as expected, as it appears the top level component/div does not have focus even though the input control does? Considering the input already has focus, I"m not sure what clicking into the input does, but it effectively solves my issue.
So, what is the difference in setting focus on the input versus clicking into this input box? Is there a way to programmatically give this input the focus it gets that matches clicking into it with mouse?
I'm using ngx-chips to create a tag input for Angular 8. I got it all to work but I would like for my input to show the dropdown whenever I focus on the tag. Currently it only shows the dropdown when I focus on the input part, which is pretty small:
I want the dropdown to show when I click anywhere on the form, like this:
Is this behavior possible? I also noticed that pressing Enter can show the dropdown, but trying to trigger that behavior on click isn't really working out.
I tried altering the CSS itself by increasing the input width, but it looks and feels weird to use. So instead, I created a workaround with jQuery.
I just created a function for the component that uses ngx-chips, and used some jQuery inside that function
showDropdown() {
$('.ng2-tag-input__text-input').click();
}
Since the dropdown appears when focusing on the tag input field, what this snippet does is exactly that, but I used this function on an outer div, so that it would seem like when you click on the whole form, the dropdown would still appear.
Hope this would help someone else as well.
The software I am debugging uses ui-bootstrap-tpls-1.1.2.
By default, if I open a modal and then click on one of the text boxes that has a a lookahead dropdown menu, the dropdown menu opens.
If I then select an option from the dropdown and click on that textbox again to pick a different option, the dropdown will not open this time, unless I delete at least one character from the original selection.
How do I get that dropdown menu to open every time I click on the text box, regardless of whether something has already been selected?
thanks
Things I've tried:
onclick="TextBoxName.Text = String.Empty;"
onfocus="this.value=''"
Clearing the textbox is not necessary, but I couldn't find anything in the documentation that would provide another way to accomplish this without clearing the text 'onclick' or 'onfocus'. Neither of those two functions above gave the result that I had hoped for.
The code for the modal:
below is a pick of the modal.
The red circle shows a textbox where a selection has already been made.
If I click on that textbox again, the dropdown will not appear until I delete at least one character from "2017/18 Items":
I am trying to get a checkbox with a label to function so that when you have text selected in a contenteditable div, clicking on the label will not lose the selection from the div. The label still needs to apply the standard checkbox tick/untick upon clicking it, but keep the focus & selection intack on the div.
Doing a simple focus() on the div won't help as the selection will be gone (and caret is at the beginning). I could of course look into a way for storing the selection object and trying to assign it back after the label click, but isn't there any simpler way of keeping the selection?
(the reason I need to do this with label & checkbox is because I will be using jQuery UI buttons and I will need the the toggle functionality of them)
On a similar note, if you click the checkbox, you usually still keep the selection in the div, but at least on FF4, if you press the checkbox very frequently (<1s), it will lose the selection. Any idea what's going on there? answered below
example: http://jsfiddle.net/niklasvh/gULM9/
It's a Firefox bug marked 490367.
According to the bug description, double-click functionality on input fields will act unusually when there is a contenteditable div on the page.
I noticed the strange behavior while trying to replicate it manually so I guessed it was a bug. I don't know of any workarounds.
I try to get the following working:
I have a form containing selectboxes and inputs.
There are two buttons on top of the virtual keyboard - "next" and "previous".
Navigating through the input fields works.
When I reach a selectbox (by pressing "next"), the keyboard stays and the selectbox shows its items.
When I select an item by tapping on an item of the selectbox, the element is selected and the keyboard disappears.
That's not what I want.
I want the next input or selectbox to be focused or the keyboard to stay.
I read (and tested) that the focus event does not work.
Is it possible to get this running by a workaround?
THX!
then assign the first responder to the next ui element and the keyboard will remain visible. You should do this in the code that accepts the input from the selectbox.
I am speculating, since there is no code included in the question, but I think the suggested approach should work