最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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);
}
发布评论

评论列表(0)

  1. 暂无评论