Sha256: aea4d92ba48f1510b28ba1d93fe3f9f75faff3f3e727ab07b7deb147e2716065

Contents?: true

Size: 1.91 KB

Versions: 125

Compression:

Stored size: 1.91 KB

Contents

// Make the autocomplete the same width as the input it is related to.
jQuery.ui.autocomplete.prototype._resizeMenu = function () {
 var ul = this.menu.element;
  ul.outerWidth(this.element.outerWidth());
};

$(document).on('ready ajaxSuccess', function() {

  $.ui.autocomplete.prototype._renderItem = function (ul, item) {
    var t = String(item.value).replace(
      new RegExp(this.term, "gi"),
      "<span class='ui-state-highlight'>$&</span>"
    );
    return $("<li></li>")
      .data("item.autocomplete", item)
      .append("<a>" + t + "</a>")
      .appendTo(ul);
  };


  $("[data-autocomplete-source]").each(function() {
    var url = $(this).data("autocomplete-source");
    var parentForm = $(this).closest("form");
    var target = parentForm.find($(this).data("autocomplete-rel"));
    $(this).autocomplete({
      appendTo: $(parentForm), // appending to the form resolves issues with autocomplete hidden in modals
      minLength: 2,
      autoFocus: true,
      open: function() { $('#div .ui-menu').width(300) },
      source: function(request,response) {
        $.ajax({
          url: url,
          data: { term: request.term },
          success: function(data) {
            var list = $.map(data, function(patient) {
              return {
                label: patient.label,
                id: patient.id
              };
            });
            response(list);
          },
          error: function(jqXHR, textStatus, errorThrown) {
            var msg = "An error occurred.  Please contact an administrator.";
            response({ label: msg, id: 0});
          }
        });
      },
      search: function(event, ui) {
        $(target).val("");
      },
      select: function(event, ui) {
        $(target).val(ui.item.id);
      }
    });
  });

  $(document).on("click", "[data-clear-value-on-click]", function() {
    var target = $(this).data("clear-value-on-click");
    $(target).val("");
  })

});

Version data entries

125 entries across 125 versions & 1 rubygems

Version Path
renalware-core-2.0.113 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.112 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.111 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.110 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.109 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.108 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.106 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.105 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.104 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.103 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.102 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.101 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.100 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.99 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.98 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.97 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.96 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.95 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.94 app/assets/javascripts/renalware/auto_complete.js
renalware-core-2.0.93 app/assets/javascripts/renalware/auto_complete.js