fitiskin / jquery-autocompleter

Easy customisable and with localStorage cache support.
https://fitiskin.ru/jquery-autocompleter/
MIT License
176 stars 85 forks source link

Spent hours trying to get this to work to no avail. #29

Closed doug-ross closed 2 years ago

doug-ross commented 6 years ago

Guys, this thing is very, very difficult to use. I have an extremley simple search box and can't get any of the list positioning to work in the most bootstrap environment.

I've spent hours fiddling with HTML and CSS and have basically given up. There should be a very simple example (the demo is useless) of the sort that jqueryui uses, stripped down and basic.

`

fitiskin commented 2 years ago

Forgive me for abandoning the project and answering you a few years later.

I've prepared an example: https://codesandbox.io/s/jquery-autocompleter-bootstrap-4-died3v CSS must be placed after defaults.

HTML

<div class="container">
  <div class="row">
    <div class="col-md-12">
      <div class="mt-4">
        <h1>jquery-autocompleter</h1>
        <p class="lead">Stripped down and basic Bootstrap 4 example</p>
        <form id="form">
          <div class="form-group">
            <label for="color">Color</label>
            <input
              type="text"
              class="form-control"
              id="color"
              placeholder="Enter color"
              aria-describedby="colorHelp"
            />
            <small id="colorHelp" class="form-text text-muted"
              >We'll never share your color with anyone else.</small
            >
          </div>
          <div class="btn-group" role="group">
            <button type="submit" class="btn btn-primary">Submit</button>
            <button type="clear" class="btn btn-light">Clear</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

JavaScript

$(function () {
  $("#color").autocompleter({
    source: data,
    customLabel: "name",
    customClass: ["custom"]
  });
});

CSS

.custom {
  z-index: 1;
  width: auto;
  box-sizing: border-box;
}

.custom .autocompleter-list {
  padding: 0.5rem 0;
  box-sizing: border-box;
  font-size: 1rem;
  color: #212529;
  text-align: left;
  list-style: none;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 0.25rem;
}

.custom .autocompleter-item {
  box-sizing: border-box;
  display: block;
  width: 100%;
  padding: 0.25rem 1.5rem;
  clear: both;
  font-weight: 400;
  color: #212529;
  text-align: inherit;
  white-space: nowrap;
  border: 0;
}

.custom .autocompleter-item:hover,
.custom .autocompleter-item-selected {
  color: #16181b;
  background-color: #f8f9fa;
}