How to set a default option in a select with data-live-search HTML?

Asked

Viewed 4,432 times

3

I need to bring in select a default option every time the page is loaded. But with the data-live-search plugin. There is this possibility?

    <div class="row-fluid">
  <select class="selectpicker" data-show-subtext="true" data-live-search="true">
    <option data-subtext="Rep California">Tom Foolery</option>
    <option data-subtext="Sen California">Bill Gordon</option>
    <option data-subtext="Sen Massacusetts">Elizabeth Warren</option>
    <option data-subtext="Rep Alabama">Mario Flores</option>
    <option data-subtext="Rep Alaska">Don Young</option>
    <option data-subtext="Rep California" disabled="disabled">Marvin Martinez</option>
  </select>

inserir a descrição da imagem aqui

I took this example from the network. I wanted when I went to view the page, by default select it to bring me a specific value. Ex: instead of bringing "Tom Foolery" according to the image, bring "Maickon" for example. Setting the value property is not working.

  • Hello, add the code that Oce already has, so it is easier to view your problem and propose a solution :)

3 answers

2

0

Dear the good is always test possible simple solutions and read the API to the fullest. So you can test future bootstrap plugins access the site Bootply.

Following the basic concept that deals with an HTML object use the full attribute to select the option: selected="selected"

see working on example that I made.

  • Got it, thanks for the example. It helped me a lot.

-1

Live search unlike SELECT is an INPUT, and it needs to receive what will be searched, and this should not be pre entered. Usually the results The right thing is to use placeholder="Tim Martin" in the input, to have a text in the background in the input. In your case there, even if you pre-fill the field it should only update after you edit at least one space. The ideal is to have nothing, because it does not work as a dead research field, it is a live research (live) .

  • Hello @David. Try putting code that supports your answer, even if it’s just an example. It’s easier to understand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.