javascript - Jquery Ui AutoComplete is not working with keyupdown when used with label value - Stack Overflow

When using keyup keydown to select option from autoplete list textbox is showing value. But incase of s

When using keyup keydown to select option from autoplete list textbox is showing value. But incase of selection from mouse it is working properly. JsFiddle -

$("#promoteActionTextBox").autoplete({
        source: actionNames,
        minLength: 0,
        select: function (event, ui) {
            event.preventDefault();
            $(this).val(ui.item.label);
            $('#promoteActionError').hide();
            $(this).attr('actionId', ui.item.value);
        },
        change: function (event, ui) {
            if (!ui.item) {
                $(this).val('');
            }
            else {

                $('#promoteActionError').hide();
                $(this).val(ui.item.label);
                $(this).attr('actionId', ui.item.value);
            }
        }
    }).focus(function (event, ui) {
        event.preventDefault();
        $('#promoteActionTextBox').autoplete("search");
        this.value = ui.item.label;
    });

When using keyup keydown to select option from autoplete list textbox is showing value. But incase of selection from mouse it is working properly. JsFiddle - http://jsfiddle/0c21r1pe/1

$("#promoteActionTextBox").autoplete({
        source: actionNames,
        minLength: 0,
        select: function (event, ui) {
            event.preventDefault();
            $(this).val(ui.item.label);
            $('#promoteActionError').hide();
            $(this).attr('actionId', ui.item.value);
        },
        change: function (event, ui) {
            if (!ui.item) {
                $(this).val('');
            }
            else {

                $('#promoteActionError').hide();
                $(this).val(ui.item.label);
                $(this).attr('actionId', ui.item.value);
            }
        }
    }).focus(function (event, ui) {
        event.preventDefault();
        $('#promoteActionTextBox').autoplete("search");
        this.value = ui.item.label;
    });
Share Improve this question edited Jan 16, 2015 at 7:23 Manjay_TBAG asked Jan 16, 2015 at 6:25 Manjay_TBAGManjay_TBAG 2,2553 gold badges24 silver badges46 bronze badges 2
  • @Innovarion - My jsfiffle link - jsfiddle/0c21r1pe/1 – Manjay_TBAG Commented Jan 16, 2015 at 7:15
  • There is problem with value change it into something like avalue then it will work – Innovation Commented Jan 16, 2015 at 10:27
Add a ment  | 

2 Answers 2

Reset to default 4

change the object property name from value to something else and it works

WORKING DEMO

UPDATE

How about THIS FIDDLE

I added a code which removes the event which is responsible for that effect.

create:function(){
    $('.ui-autoplete').unbind('menufocus');
}
select: function(event, ui) {
    event.preventDefault(); // Add on keyboard keyup, keydown is working well
    $("#id_value").val(ui.item.value);
    $("#id_label").val(ui.item.label);
},
focus: function( event, ui ) {
    event.preventDefault(); // Add on keyboard keyup, keydown is working well
    $("#id_value").val(ui.item.value);
    $("#id_label").val(ui.item.label);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745531352a4631709.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信