2

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 ?!

Roman C
  • 49,761
  • 33
  • 66
  • 176
Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173

1 Answers1

2

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())
});
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • 1
    Thanks @Roman ! So it seems that this feature is not working and we should use this workaround until bug fix. – Alireza Fattahi Jan 07 '15 at 04:22
  • Your code will only set the hidden value which is associated to this input. If you want that the input shows the user value `$(".s2j-combobox-input.ui-autocomplete-input").blur(function(e){ $(".s2j-combobox-input.ui-autocomplete-input".val( $("#sample").val() ) });` – Alireza Fattahi Jan 28 '15 at 11:32