Changes between Initial Version and Version 2 of Ticket #15154


Ignore:
Timestamp:
Mar 22, 2017, 4:25:47 AM (6 years ago)
Author:
maglioccola
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #15154 – Description

    initial v2  
    1 
    2 {{{
    3 var mySource = [{"label":"Value one","id":"1"},{"label":"Value two","id":"2"},{"label":"Value three","id":"3"}];
    4 
    5 $("#txtAutocomplete").autocomplete({
    6   source: mySource,
    7   select: function(event, ui){
    8     if(ui.item){
    9       //console.log('select', ui.item.label);
    10       $("#hiddenField").val(ui.item.id);
    11       return ui.item.label;
    12     }
    13     else{
    14       //console.log('select with null value');
    15       $("#hiddenField").val('');
    16     }
    17   },
    18   change: function(event, ui){
    19     if(ui.item){
    20       //console.log('change', ui.item.id);
    21       $("#hiddenField").val(ui.item.id);
    22     }
    23     else{
    24       //console.log('change with null value');
    25       $("#hiddenField").val('');
    26     }
    27   }
    28 });
    29 
    30 <link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
    31 <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
    32 <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    33 <p>
    34   <ol>
    35     <li>Type 'Value' in the text box</li>
    36     <li>Press 'arrow down' to select the first element</li>
    37     <li>Press enter</li>
    38     <li>Keep pressed backspace to delete completely the selected item</li>
    39     <li>Press TAB</li>
    40     <li>Value in 'readonly' field is still there</li>
    41   </ol>
    42 </p>
    43 
    44 <input type="text" id="txtAutocomplete">
    45 <input type="text" id="hiddenField" disabled="disabled">
    46 
    47 <button>Button added just to have an element to focus on</button>
    48 }}}
     1I provided a simple snippet, please see: [https://jsfiddle.net/zcaszs38/2/]
    492
    503When I put the string 'value' in the editable field, autocomplete appears correctly, so I can select one value and put it in the textbox with id hiddenField. Then, if I clear the value in the textbox, I can't update the related hiddenField with a blank value, because change event doesn't fire. Why?