Struts 2 jquery autocompleter with forceValidOptio

2020-03-26 17:26发布

I have set the Struts 2 jquery auto complete tag forceValidOption to false as:

<sj:autocompleter list="destinationAccounts" id="sample" 
            listKey="accountNo" name="toAccount"
            listValue="%{accountNo + \" \" + firstName + \" \" + lastName }"
            forceValidOption="false"/>

The forceValidOption is not working and it forces the user to select from options and will auto-clean user entered data, when user leaves input. The generated javascript is as:

var options_sample_widget = {};
options_sample_widget.hiddenid = "sample";
options_sample_widget.selectBox = true;
options_sample_widget.forceValidOption = false;

options_sample_widget.jqueryaction = "autocompleter";
options_sample_widget.id = "sample_widget";
options_sample_widget.name = "toAccount.accountNo_widget";
options_sample_widget.href = "#";
options_sample_widget.formids = "ownToOtherForm";


jQuery.struts2_jquery_ui.bind(jQuery('#sample_widget'),options_sample_widget);

It shows that the forceValidOption is set.

Should I set other options to make it work?!

I have test it in the showcase and still I could not make it work.

If there is a bug here, can I use jQuery autocomplete function directly and disable this feature ?!

1条回答
一夜七次
2楼-- · 2020-03-26 17:59

The autocompleter without href attribute is used to load a static list.

If it's used with selectBox="true", it renders select tag to hold its options and two input fields: one is a hidden field which value is submitted, and another is a combobox. The value from this field should be set to a hidden field. To make it work you should set the following function

$(".s2j-combobox-input.ui-autocomplete-input").keyup(function(e){
  $("#sample").val($(".s2j-combobox-input.ui-autocomplete-input").val())
});
查看更多
登录 后发表回答