0

I use autocomplete to populate a textbox in a jquery datatables grid. Sometimes the string returned is longer than the textbox. Once it is selected I do not see the beginning of the string, I only see the end. One solution would be to truncate the string selected so it never is too long for the textbox. But this could confuse the user.

Is there a better way?

<tr  @if (Model != null) {
         @:data-pkey='@Html.AttributeEncode(Model.TimeEntryRowID)'
     }    >
    <td style = "width:380px">
        @Html.TextBoxFor(x => x.JobDescription, new { @class = "JobDescriptionList", style = "width:370px;text-align:left;" })
        @Html.HiddenFor(x => x.JobName, new { @class = "JobName"})
    </td>



$(".JobDescriptionList").autocomplete({
    source: arrayJobs,
    minLength: 2,
    mustMatch: true,
    select: function (event, ui) {
        var $input = $(this);
        var TABKEY = 9;
        if (event.keyCode == TABKEY) {
            // tabout was not moving to next box
            $input.next('input').focus();
        }
    },
    change: function (event, ui) {
        if (ui.item) {
            var $input = $(this);
            //var contractShort = GetContractShortened(ui.item.value);
            var contract = ui.item.value;
            $input.val(contract);
            var $jobName = $input.closest("td").find(".JobName");
            var contractNo = GetContractNo(contract);
            $jobName.val(contractNo);
        }
arame3333
  • 9,887
  • 26
  • 122
  • 205
  • 1
    I would try to place the cursor in the textbox before the first letter. – developer10214 Oct 18 '13 at 08:48
  • I tried using select(0,0) in the change function but that did not work. – arame3333 Oct 18 '13 at 09:37
  • Actually you are correct, I found out how to do it here; http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area and this has solved the problem – arame3333 Oct 18 '13 at 09:55
  • However ... once I have selected an item I then want to tab to the next textbox. When this happens, all I see is the end of the string again. – arame3333 Oct 18 '13 at 10:14

1 Answers1

0

According to the comments the solution is: - place the cursor in the textbox before the first letter - the answer of this question (jquery-set-cursor-position-in-text-area) shows how to do it.

Community
  • 1
  • 1
developer10214
  • 1,128
  • 1
  • 11
  • 24