アプリケーションの 1 つでAjax Autocomplete for Jquery
( http://www.devbridge.com/projects/autocomplete/jquery/ )を使用しています。検索フォームは次のようになります。
<form id="topsearch" method="POST" action="/searchAll"><input type="text" class="searchform" name="q" id="q" value="Country, City, Hotel or a Tourist Attraction" o nfocus="clearInput(this);" onblur="defaultInput(this);" />
<select id="top_search_select" name="entity_type">
<option value="country">Countries</option>
<option value="city">Cities</option>
<option value="place" selected="selected">Tourist Attractions</option>
<option value="hotel">Hotels</option>
</select>
<input type="submit" name="topsearch" class="submit" value="SEARCH" title="SEARCH"/>
</form>
オートコンプリート構成は次のようになります。
<script type="text/javascript">
//<![CDATA[
var a = $('#q').autocomplete({
serviceUrl:'/search',
delimiter: /(,|;)\s*/, // regex or character
maxHeight:400,
width:325,
zIndex: 9999,
params: {entity_type:$('#top_search_select').val()},
deferRequestBy: 0, //miliseconds
noCache: false, //default is false, set to true to disable caching
onSelect: function(value, data){window.location.replace(data);},
});
//]]>
</script>
問題はバックエンドにあり、ユーザーがフォームの選択オプションで選択するさまざまなタイプのエンティティの結果を生成するさまざまなハンドラーがあります。
デフォルトentity_type
ではplace
、バックエンドのハンドラーに問題なく渡されます。ただし、スクリプト構成のフォームの選択ボックスから別のエンティティを選択すると、人params: {entity_type:$('#top_search_select').val()}
も更新されます。
どんな助けやアイデアも大歓迎です。ありがとう。