5

मैं यह करने की कोशिश कर रहा हूं http://jqueryui.com/autocomplete/#combobox समस्या यह है कि जब मैं एक विकल्प पर माउस के साथ जाता हूं, तो विकल्प गायब हो जाएंगे और यह सलाह देगा: "x किसी से मेल नहीं खाता वस्तु "जहां x अक्षर हैं जो मैंने combobox में लिखा था।Jquery ui combobox (स्वतः पूर्ण) गायब हो जाता है

(function($) { 
$.widget("ui.combobox", { 
    _create: function() { 
    var input, 
     that = this, 
     wasOpen = false, 
     select = this.element.hide(), 
     selected = select.children(":selected"), 
     value = selected.val() ? selected.text() : "", 
     wrapper = this.wrapper = $("<span>") 
     .addClass("ui-combobox") 
     .insertAfter(select); 

    function removeIfInvalid(element) { 
     var value = $(element).val(), 
     matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(value) + "$", "i"), 
     valid = false; 
     select.children("option").each(function() { 
     if ($(this).text().match(matcher)) { 
      this.selected = valid = true; 
      return false; 
     } 
     }); 

     if (!valid) { 
     // remove invalid value, as it didn't match anything 
     $(element) 
      .val("") 
      .attr("title", value + " didn't match any item") 
      .tooltip("open"); 
     select.val(""); 
     setTimeout(function() { 
      input.tooltip("close").attr("title", ""); 
     }, 2500); 
     input.data("ui-autocomplete").term = ""; 
     } 
    } 

    input = $("<input>") 
     .appendTo(wrapper) 
     .val(value) 
     .attr("title", "") 
     .addClass("ui-state-default ui-combobox-input") 
     .autocomplete({ 
     delay: 0, 
     minLength: 0, 
     source: function(request, response) { 
      var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i"); 
      response(select.children("option").map(function() { 
      var text = $(this).text(); 
      if (this.value && (!request.term || matcher.test(text))) 
       return { 
       label: text.replace(
        new RegExp(
        "(?![^&;]+;)(?!<[^<>]*)(" + 
        $.ui.autocomplete.escapeRegex(request.term) + 
        ")(?![^<>]*>)(?![^&;]+;)", "gi" 
       ), "<strong>$1</strong>"), 
       value: text, 
       option: this 
       }; 
      })); 
     }, 
     select: function(event, ui) { 
      ui.item.option.selected = true; 
      that._trigger("selected", event, { 
      item: ui.item.option 
      }); 
     }, 
     change: function(event, ui) { 
      if (!ui.item) { 
      removeIfInvalid(this); 
      } 
     } 
     }) 
     .addClass("ui-widget ui-widget-content ui-corner-left"); 

    input.data("ui-autocomplete")._renderItem = function(ul, item) { 
     return $("<li>") 
     .append("<a>" + item.label + "</a>") 
     .appendTo(ul); 
    }; 

    $("<a>") 
     .attr("tabIndex", -1) 
     .attr("title", "Show All Items") 
     .tooltip() 
     .appendTo(wrapper) 
     .button({ 
     icons: { 
      primary: "ui-icon-triangle-1-s" 
     }, 
     text: false 
     }) 
     .removeClass("ui-corner-all") 
     .addClass("ui-corner-right ui-combobox-toggle") 
     .mousedown(function() { 
     wasOpen = input.autocomplete("widget").is(":visible"); 
     }) 
     .click(function() { 
     input.focus(); 

     // close if already visible 
     if (wasOpen) { 
      return; 
     } 

     // pass empty string as value to search for, displaying all results 
     input.autocomplete("search", ""); 
     }); 

    input.tooltip({ 
     tooltipClass: "ui-state-highlight" 
    }); 
    }, 

    _destroy: function() { 
    this.wrapper.remove(); 
    this.element.show(); 
    } 
}); 
    })(jQuery); 

    $(function() { 
    $("#combobox").combobox(); 
    }); 

और सीएसएस: अब मैं स्क्रिप्ट साइट पर है कि पोस्ट

.ui-combobox { 
position: relative; 
display: inline-block; 
} 
.ui-combobox-toggle { 
    position: absolute; 
    top: 0; 
    bottom: 0; 
    margin-left: -1px; 
    padding: 0; 
    /* support: IE7 */ 
    *height: 1.7em; 
    *top: 0.1em; 
} 
.ui-combobox-input { 
    margin: 0; 
    padding: 0.3em; 
} 

और मेरे चयन (JSP साथ builded)

<select id="combobox"><option value="">Select one...</option> 
            <%for(int i=0;i<ut.size();i++){ 
            out.print("<option value=\""+ut.get(i).getIdUtente()+ 
              "\">"+ut.get(i).getNome()+" "+ut.get(i).getCognome()+" ("+ut.get(i).getIdUtente()+")"+"</option>"); 

            } 
             %> 

            </select> 

अब, जहां है मेरी मुसीबत? अग्रिम धन्यवाद!

उत्तर

13

यह मेरे साथ भी हुआ। ऐसा लगता है कि jQuery UI जेएस फ़ाइल को दो बार बुलाया गया था। एक निकालें और यह

+0

+1 यह पता लगाने के लिए एक कठिन था। मेरे पास jQuery UI के पुराने और नए संस्करणों के लिंक थे। – nima

+0

हाहाहा धन्यवाद मेरा भी कठिन था। एक को सामान्य रूप से हेडर में बुलाया जाता था, दूसरा जावास्क्रिप्ट के माध्यम से गतिशील रूप से कहा जाता था: एस। – bicycle

+1

मैंने प्रतिलिपि उस कोड को चिपकाया था ताकि यह समस्या हो। समस्या की पहचान करना मुश्किल था। @ साइकिल के सुझाव ने मेरे लिए काम किया –

3

यह संबंधित परिदृश्य में होगा जहां आप प्राथमिक jQuery UI (jquery-ui.js) लाइब्रेरी और एक ही समय में jquery ui autocomplete के लिए व्यक्तिगत पुस्तकालयों का संदर्भ लेंगे। JQuery-UI फ़ाइल में सभी बच्चे शामिल हैं इसलिए दोनों को संदर्भित करने की आवश्यकता नहीं है।

+0

यह मेरी समस्या हल हो गया। मैं डुप्लिकेट जेएस फाइलों की तलाश में था जैसे सभी सुझाव देते हैं। जैसा कि यह पता चला है, jquery-ui.js में सभी व्यक्तिगत फ़ाइलें शामिल हैं। – Yorro

+0

धन्यवाद, दोस्त। उसने मेरे लिए इसे हल कर दिया। – devKoen1

संबंधित मुद्दे