See the code example below. When you select the text in the first input and drag it to the second input, what you are left with in the second input is just the text 'questions'.
Can anyone explain why this happens and if there's a way to keep all the text when dragging?
Thanks!
<input type="text" value="http://stackoverflow.com/questions"/>
<input type="text"/>
Attempt to drag some text from a text input to an empty text input. It will fail, and will raise an assert in debug builds:
ASSERT(oldLength >= selectionLength);
I think this is because WebCore is calculating oldLength from the wrong element; it looks like it's calculating the length of the text field being dragged to rather than the text field being dragged from.
Related
all. I'm curious to know if the regular text input (not text area) could detect multiple lines value. If I copy any string that has various lines and pastes it into a standard input box, it will display as a single-line string and has no idea whether it has multiple lines or a single line.
I just want to know if we can preserve the original value (with multiple lines)
Original string value
INVOICE_500
INVOICE_501
After pasting it into the regular text input
INVOICE_500 INVOICE_501
Thanks in advance.
I found an article from a previous post where an way has been shown. We can use clipboard API as it copy text as it was written. It was applied on a div. I have converted it on a input field. I have attached the code below. Hope this might help you.
Reference article: Clipboard data on paste event
function handlePaste(e) {
var clipboardData, pastedData;
// Stop data actually being pasted into input
e.stopPropagation();
e.preventDefault();
// Get pasted data via clipboard API
clipboardData = e.clipboardData || window.clipboardData;
pastedData = clipboardData.getData('Text');
// Do whatever with pasteddata
alert(pastedData);
}
document.getElementById('pasteInput').addEventListener('paste', handlePaste);
<input id='pasteInput' placeholder='Paste text here'></div>
No you can't, the only HTML input element that's designed to be multi-line is the "textarea" element.
<textarea name="textArea" cols="40" rows="5">
In this scenario the input field is limited to 5 Characters for the user to enter, once the user enters the 5 characters I append programatically a kind of description for the input to it (USER-Description).
Since the actual input will be the users input i want that to be limited to 5 but I should be able to programatically add a string of any length. When I do this currently the input field stays Red as if the required flag is on.
I think below points may help
You can add a empty box and maxLength Validation on (focus). and on (blur) remove the validation and apeend extra text.
or
you can do via css Trick, make a input group box. (input + div). (search input-group bootstrap for more info).
Have input a validation of 5 charter in input box and on focus and blur play with your append logic.
point 1 code will look something like this
<input type="text"
(focus)="firstName.maxLength = 5"
(blur)="appendString()"
name="firstName" [(ngModel)]="model.firstName" #firstName="ngModel" required />
The search bar here uses the following code with placeholder text and en empty value to search everything by default:
if(CleanSQLText(Request.Querystring("Q"))="") then
SearchQuery=""
<input type="text" placeholder="e.g. Shops" name="Q" value="<%=SearchQuery%>" onclick="if (this.defaultValue == this.value) { this.value = ''; }">
The problem is when no value is entered and no selects chosen, the results keep using the old value 'e.g. Shops', which changed to placeholder text.
Search results heading:
<h2 class="searchResults">Businesses matching "<%=SearchQuery%>"</h2>
How can that happen when there is no value?
The placeholder text is actual text in the box. And ASP.NET is doing something funky to get it to behave like it does. I haven't used it too much because of ASP.NET's weirdness but its perfectly valid.
What is happening is that the text box has your prompt text and they click search so it isn't empty like you think it should be.
You could put an if(text != 'My Prompt Text').
If your prompt text is a valid search the user could use, then I would suggest you track if the user has clicked on the text box with jQuery, the onclick even, and a Boolean stored as an attr on that element.
I am currently trying to build a simple form and I want one of the entries to have a large textbox to enter a large amount of data. However in order to do this, it seems I must have two text boxes, like the following:
(This one to initiate the "bigBox")
<input type ="text" name = "bigBox">
(This one to make the big box)
<textarea rows = "4" cols = "50" name = "bigBox"> </textarea>
However when I implement the solution like this I am left with two text boxes. How can I remove the initial "input" box but keep the text area one and still allow the user to submit their form as per usual?
Thanks in advance,
Markk1
You can consider textarea an alias of input, so to speak - just that it will be a large area for text not a single row input box. You don't need the first input in order to "initiate" the the textarea - it is by itself already capable of storing input.
I've one text box and one update button:
Text box:
<asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
update button:
<asp:Button ID="btnUpdFName" runat="server"Text="Update" onclick="btnUpdFName_Click"/>
What I am doing in page load event I am getting the first name from database and assinging it to text box as follows:
txtFName.Text = dt.Rows[0][1].ToString();
Now when i earases the text set at page load event in text box as above and write another name and press update button, i am trying to get the new text entered in the text box in the button click event as follows:
string FName = txtFName.Text;
But the problem is that every time I write new text in text box, I am still getting the same text as set form database (dt.Rows[0][1].ToString()).
I am not able to get the current text from the text box and getting only the intial value set from db in page load event.
What I encountered that after compilation my text box markup becomes as follows:
<input id="CPHcontent_txtFName" type="text" value="value set from db i.e. dt.Rows[0] [1].ToString()" name="ctl00$CPHcontent$txttxtFName"></input>
the text box alway has the same value set from the db. Thats why i am getting each time the same value regardless of value entered by user in text box.
Now tell me how to get the updated value of text box in my page behind.
Thanx in advance
In asp.net webforms you should separate code for setting data to control and for saving data to db. One of ways to set data to control - use check
if (!IsPostBack)
{
txtFName.Text = dt.Rows[0][1].ToString();
}
in page load event.
Otherwise you will overwrite your newly entered text for textbox on every page load.
You are probably overwriting the text you entered in your Page Load event, because you are not checking if it is a PostBack.
Please read ASP.NET Page Life Cycle Overview for further information.
Set the textbox to empty or null before you try to set/read it again onpageload.