ShihMingSyu / struts2-jquery

Automatically exported from code.google.com/p/struts2-jquery
0 stars 0 forks source link

<sj:autocompleter selectBox="true" selectBoxIcon="true" not work with jso #488

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
(This is for feature requests and bugs in Struts2 jQuery Plugin - for
getting help, please use the User Group.
http://groups.google.com/group/struts2-jquery )

What steps will reproduce the problem?
1.<sj:autocompleter selectBox="true" selectBoxIcon="true"
2.Type something or click selectBoxIcon
3.No Ajax request

What is the expected output? What do you see instead?

Which struts2 version? 2.2.1

Which struts2-jquery plugin version? 2.5.1

Please provide any additional information below.

Original issue reported on code.google.com by jflefeb...@sopragroup.com on 30 Mar 2011 at 12:16

GoogleCodeExporter commented 9 years ago

Original comment by johgep on 1 Apr 2011 at 9:29

GoogleCodeExporter commented 9 years ago
Is this issue already exists with latest version?

Original comment by johgep on 12 Nov 2011 at 11:34

GoogleCodeExporter commented 9 years ago
Yes I reproduce it whith the last version

Original comment by jflefeb...@sopragroup.com on 14 Nov 2011 at 8:49

GoogleCodeExporter commented 9 years ago
The autocompleter with selectBox is working with an static list. In your use 
case you should use the <sj:select /> tag with autocomplete="true" instead. 

<s:url id="remoteurl" action="jsonsample"/> 
<sj:select
         href="%{remoteurl}"
         autocomplete="true"
         id="echo3"
         name="echo"
         list="languageObjList"
         listKey="myKey"
         listValue="myValue"
         emptyOption="true"
         headerKey="-1"
         headerValue="Please Select a Language"/>

Original comment by johgep on 14 Nov 2011 at 11:47

GoogleCodeExporter commented 9 years ago
Sorry but that does not work.
I would like to have (like struts 2 dojo autocompleter) an autocompleter that 
complete in ajax and have the possibility to select an item with the selectbox 
(ajax mode)

Original comment by jflefeb...@sopragroup.com on 16 Nov 2011 at 7:25

GoogleCodeExporter commented 9 years ago
Any idea to make it work with JSON ?

Original comment by jflefeb...@sopragroup.com on 10 Feb 2012 at 8:54

GoogleCodeExporter commented 9 years ago
Pleuse find my code to enable this fonctionnality. Do you wich to include it 
into your very good framework !!!!

// Met un max width a la liste de tous les autocompleters de la page
    // et autorise vide comme option valide
    var originalAutocompleterFunction=jQuery.struts2_jquery_ui.autocompleter;
    jQuery.struts2_jquery_ui.autocompleter = function($elem, options) {

        originalAutocompleterFunction.call(this,$elem, options);

        // Vide est une option valide
        if(options.forceValidOption) {      
            $elem.keyup(function(event) {               
                var val = $elem.val();
                if(!val){
                    jQuery(jQuery.struts2_jquery.escId(options.hiddenid)).val('');
                }
            });
        }

        $elem.autocomplete('widget').css("max-width", $elem.width());

        if(options.selectBoxIcon && !options.selectBox) {
            jQuery.struts2_jquery.require([ "js/base/jquery.ui.widget" + self.minSuffix + ".js", "js/base/jquery.ui.button" + self.minSuffix + ".js", "js/plugins/jquery.combobox" + self.minSuffix + ".js" ]);

             var initialMinLength = $elem.autocomplete( "option", "minLength" );
             var height = $elem.outerHeight(true);
             //var buttonId = 'autocompleter_fleche_'getUniqueId();
             var button = jQuery("<button type='button'> </button>")
                .attr("tabIndex", -1)
                //.attr("id", buttonId)
                .attr("title", "Show All Items")
                .insertAfter($elem).button({
                    icons: {
                        primary: "ui-icon-triangle-1-s"
                    },
                    text: false
                })
                .css( "marginLeft", "-1px" )
                .css( "width", height )
                .css( "height", height )
                .removeClass("ui-corner-all")
                .addClass("ui-corner-right ui-button-icon")
                .click(function() {

                    // close if already visible
                    if ($elem.autocomplete("widget").is(":visible")) {
                        $elem.autocomplete("close");
                        return;
                    }

                    // work around a bug (likely same cause as #5265)
                    jQuery(this).blur();

                    // pass empty string as value to search for, displaying all results
                    $elem.autocomplete({ minLength: 0 });
                    $elem.autocomplete("search", $elem.val());
                    $elem.focus();
                    $elem.autocomplete({ minLength: initialMinLength });
                });

                button.find(".ui-button-icon-only .ui-button-text").css( "padding", "0.35em" );
                button.css( "margin", 0 ).css( "padding", "0.48em 0 0.47em 0.45em;" );;
                button.position({
                    of: $elem,
                    my: "left center" ,
                    at: "right center" ,
                    offset: "0 0"
                });

        }
    };

Original comment by jflefeb...@sopragroup.com on 23 May 2012 at 7:22