Rails3中-jquery的,自动完成清场,如果没有可用的数据 [英] rails3-jquery-autocomplete clear field if no data available
本文介绍了Rails3中-jquery的,自动完成清场,如果没有可用的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Rails3中,jquery的,自动完成。是否有可能清楚,如果自动完成返回任何结果的自动完成字段的值?我试图prevent用户数据库提交我们没有值。
I am using rails3-jquery-autocomplete. Is it possible to clear the value of an autocomplete field if the autocomplete returns no results? I'm trying to prevent users from submitting values we don't have in database.
推荐答案
我使用的是旧版本,但我实现了一个变更
处理程序自动完成()
电话。
I am using an older version but I implemented a change
handler for the autocomplete()
call.
$('input[data-autocomplete]').live('focus', function(i){
$(this).autocomplete({
// ...
change: function(event, ui) {
var $this = $(this);
// blank if nothing was selected
if (!ui.item) {
$this.val(null);
var id_selector = $this.attr('id_element');
if (id_selector)
$(id_selector).val(null);
}
}
});
});
这篇关于Rails3中-jquery的,自动完成清场,如果没有可用的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文