how to use jquery validation with jquery autocomplete in my code

▼魔方 西西 提交于 2019-12-04 19:10:57

Looks like your jquery validator kicks in before autocomplete puts the selected value in your city box - so in your example, "a" (instead of "Cape Town") is getting validated.

You might be able to fix this by populating the city box "faster" using onRollover callback (instead of waiting the user to make a selection). I don't know what autocomplete library that you are using, but I'm looking at this one http://www.codenothing.com/demos/2009/auto-complete/docs/ and you should be able to do something like this:

    jq('.city').autoComplete({
        onRollover: function(event, ui){
            jq('.city').val(ui.data.value)
        }
    });

um you have a duplicate id IN THERE:

 id="textarea_small" 

Having fixed the above, you will need to intercept the validation event to force it to fire AFTER the selection event - with the jQuery UI Autocomplete, that is pretty easy ie

...
select: function(event, ui) {
    var selectedValue = ui.item.value;
    var focusedElement = $(this);
    // my pretend function checkData OR add a validation event fire here.
    checkData(focusedElement, ui.item, selectedValue);
    return false;
},
...

I am not familiar with the plug-in you are using but it should have something like that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!