We're looking for a certain type of control, preferably with a Bootstrap implementation. We don't believe it's really uncommon, but we might be wrong.
It's essentially a listbox, but also:
It's like an editable combobox, but without a dropdown.
Like a tag input/pillbox, but vertical, with a more traditional style, and directly editable.
Like an expanding grid, but with a single column.
Like a series of vertically attached text input field boxes, on steroids.
Like a text area, but properly structured and expanding.
The ultimate goal is to be able to quickly and efficiently input a bunch of values (phone numbers, ...) without leaving the keyboard, while allowing the user to edit or remove existing values painlessly. (The form is relatively large and part of a LOB application.)
Does this control have a name?
Does anyone know of a Bootstrap plugin that provides such a control?
If not, then we're not exactly sure about how to proceed, would you have any pointers for us so that we can implement this in a straightforward way? (Is it a good idea to start with a series of text input fields for example?)
Details:
It's essentially a list,
It starts as something that looks very much like a simple text input field,
When the user presses ENTER, a new row is added below and the cursor is moved to it (the list expands dynamically),
When the user presses TAB, the cursor is moved to the next control,
(Optional) When the user presses the UP or DOWN arrow key, the cursor jumps in the previous or next element, respectively,
Each row is directly editable (the user can click inside any of them and change any character, even in the middle, thus without deleting the element first),
(Optional) There can only be one empty row at the end,
(Optional) If the user focuses another control (for example by pressing TAB) or another element (for example by using the arrow keys or by clicking), the current element is removed if it's empty,
(Optional) In addition to pressing ENTER when the cursor is in the last field, the user can press a button to add a new empty element if the last element is not empty,
There is only one column (no need for a column header),
(Optional) An inline label should be displayed in the last element if it's empty,
There is a button next to each element that allows the user to remove them,
(Optional) When the user presses DELETE twice at the end of an element, the focused element is removed (it must be pressed twice so that a user who keeps the button pressed to delete a bunch of characters doesn't remove the element by accident if that wasn't her intention -- this requirement can be formulated in other ways),
(Optional) The user can undo a delete operation,
(Optional) If the number of elements exceeds a certain limit, a scroll bar appears and the height of the control is fixed at that limit,
(NTH) If the number of elements exceeds a second (normally higher) limit, the list is paginated.
As I don't know any control that suits your needs, I'll try to suggest some implementation options:
Contenteditable:
Take a look at the contenteditable attribute - demo here.
This won't match all your requirements (point 12 is the main blocker here), but it's pretty nice OOTB, and (according to MDN) cross-browser.
The demo provided above may be a good starting point for your own solution.
One input per line:
The other approach will be to use one input for each of the lines.
I've provided simple demo that adds "new line" as enter is pressed.
Although this implementation will also need a bit of boxing with keyboard events, this one-element-per-line model seems to better reflect your bussiness needs and is pretty flexible.
I'd be afraid about performance with bigger data sets, though.
This can be also mixed with contenteditable approach (e.g. list of editable <li> elements), but it doesn't seem to bring in any benefits. It even brings some problem, because contenteditable won't restrict number of lines by default; with regular input, you have a guarantee that one element contains one line.
Related
I'm building project Word like on contentEditable.
I know this is not the best choice to make in case of rich text editors, but still I want to track changes in the document by user, with peer-review in the end by supervisor.
I have a state, isTrackingChanges, when true - it's overrides actions, as - on insert text, insert node with underline, on backspace - get a deleted character, insert node with strikethrough style, move caret by one character to the left. At this point I have a lot of inline nodes. But on peer review I would like to accept/decline whole part of characters. How can I group them programmatically?
Fixed the problem with another solution. On accept/decline change I'm checking for Node.nextSibling() and Node.previousSibling() to get whole group. Works fine for me
I am trying to do a type of calculator that calculates the Body Mass Index of a person. It works real nice if I input the actual value (I use jQuery to make the calculus).
What I want to do though, is that instead of typing the value, the user to be able to write it from the numbers buttons, so it works like a calculator.
The problem I have is that I can't find how to know if an html input is selected. This is necessary since I will use the same "keyboard" for two different inputs (One to enter weight and another one for height).
I put below an image of how it works. Same keyboard for two different inputs.
Problem:
I think you are complicating the issue by attempting to use the same keyboard for two inputs. If you want to achieve your goal in this manner, you will need to:
add event listener to each input ('click' event)
change how the keyboard behave depending on which input is selected (heavy work!)
Solution:
Prepare a keyboard for each input.(two keyboards in total) That way, you only have to:
display the keyboard for the input selected
You can either use CSS selector or JavaScript to handle displaying the appropriate keyboard. I think it is so much simpler than using 'the same keyboard'.
With HTML/JS, I'd love to create a UI control for tweaking numbers.
Requirements
I'd love to support a coarse-vs.-fine scheme, i.e., reuse the space of a range control for a number input, so that workflow for tweaking a number would look like this:
Drag the slider to enter the rough zone;
Double-click the slider and see the input control in place while the range turns invisible;
Enter the accurate number;
Press Escape on keyboard and see the range control again, and the input becomes invisible.
Would this be possible? If so, I need some pointers how to do this. Would it be an overlay or remove/add/refresh cycles? I honestly have no idea how.
This should be possible by setting the value of the range control directly.
It could be as simple as listening for mouse events on the slider, hooking into one of these, showing a modal that has one input prefilled to the existing value on the slider, allowing the user to change the value directly.
Upon 'submitting' this modal update the value of the slider i.e document.getElementById("slider").value = 123;
I've had a horrible problem that I've been wracking my brain for the past two days for, and have yet to come up with a solution. As such, I think this needs someone smarter than I to accomplish.
What I'm trying to build is a textbox that simulates that of Facebook's; essentially, the tagging function.
Now if you've used Facebook, you'll have noticed that Facebook allows you to tag people in a comment/post, simply by typing in their name and selecting from a dropdown list. The name of the person you've selected then appears in highlighted text in that very textarea. I've successfully managed to create and populate the dropdown list a combination of JQuery and AJAX, but the tagging process itself is the stumper.
Once a dropdown item has been selected (by Enter or clicking), the query text will be replaced with the tagged name. Now, it's difficult to see how one can give text in a textarea any kind of a highlight, so I've discovered (by inspecting elements in Google Chrome and deleting the textarea node) that the textarea itself is transparent, and there is a white div below "simulating" the text. Highlighted words are placed in a tag with custom CSS, which gives it that blue background. All of this I've found out myself, and I have successfully simulated this - but I can only do one tag.
Now I've investigated further and found an input type="hidden" element, of class "mentionsHidden". This input element has a value attribute, which dynamically populates itself based on the content of the textarea. So if I typed "ABC", the value of the element becomes "ABC". If I included a tag, say "hi [Rei]!" (where the name in [] is the tag), the value of the element becomes "hi #[member_id:Rei]!".
So I HAVE done my homework. But here comes the part I can't figure out.
I can't figure out how exactly to dynamically populate the hidden input element with the value of the textbox. It's obvious that the underlying div giving the blue tag background is populated from the input element. But the input element is giving me a headache.
You see, I can't do the following:
-I can't simply "copy" the entire value of the current textarea and "paste" it into the input element's value, because that would override any previously tagged people in the input element (after all, the textarea can only possess plaintext).
-Even though I CAN locate the current index of the caret (the flashing black line in the textarea that tells you where you're going to be typing into), that's only for the textarea. Index position 10 in the textarea and in the input element's value might be different things, because this way of "tagging" people will result in adding additional characters to the value String.
-I can't simply do a "replace" of the text I am intending to replace, because there might be other instances of that same text in other parts of the value String.
I know it's a very long and confusing post, but I do hope you get what I mean. I really need a solution and I don't want to use contenteditable, because it's only for HTML5 and some older browsers might not support it.
Yours,
Rei
I hope you were able to come up with, or find, a solution to your problem. Since there doesn't seem to be one here, i'd like to offer one for and anyone who might stumble upon this (as well as you if my assumption was incorrect).
You are going to need to maintain explicit locational data of each existing mention in the textarea in the order in which they appear. If, after a modification of the content in textarea, the position of a mention in it is changed, you will need to determine which appearance of its value, if any, will be used to represent it, and appropriately update the locational data of the mention.
With such a collection of data, it becomes trivial to construct the value of mentionsHidden, though the existence of such data makes the element unnecessary.
Mentionator is an existing, robust solution which takes this approach in providing the functionality you are trying to recreate. Considering it is well-structured, easy to follow, and copiously commented, it should be of use to you as either out-of-the box solution or reference material to cite as you roll out your own. It is maintained by yours truly :) .
i know <textarea name="textarea" disabled="disabled">dsds</textarea> can disable write in the textarea ,
but how to disable one line i want to disable in the textarea ?
not all line
thanks
That's not possible without JavaScript, even then:
You need to enable contentEditable
You need to write your own editor...
You need to figure out what happens if someone deletes or inserts a line and therefore moves the disable one around
You need to figure out what to do when someone hits enter in the line above the disabled one or backspace at the beginning of the line below the disabled one...
To sum it up, a textarea is the wrong approach here, better use multiple input's for whatever you want to do here, of course you will need to make it look like it's one textarea and you'll still need some JavaScript to make return work as expected (?), but then again you didn't specify what you want to do with this stuff.
Yes, use multiple input texts appear like a single text area, let's call it fake text area. That way disabling one would be easy.
Do not put any margin in between them and no border, all having same width.
Assign incremental ids to each one - like input-1,input-2 etc.
If you want to prefill some text into the fake textarea, calculate the maximum length that can be accomodated into a single input and fill line by line using javascript (jquery would be better).
When cursor is at the end of an input text and enter is pressed, take cursor to next text input. Define a function for every such possibility and call it.
On posting the form, append the input values together to get the actual value of the faked text area.
I guess there may be difficulties in faking a scrollbar for such a textarea but once implemented, should work fine. Any existing plugins like this?
Updates
- For handling cursor positions, refer these things. I did not try myself but may be useful - Jquery Caret position and How to get cursor position in textarea and you can apply the cursor position getting-setting logics. Somehow try to get the actual click position and force the cursor to stay there.