Bootstrap-select: Dropdown with country flag img

Created on 15 Jun 2017  路  5Comments  路  Source: snapappointments/bootstrap-select

How I can to drop select option with img icon. exp. countries flag.
Similar http://js.nicdn.de/bootstrap/formhelpers/docs/country.html
Thx,

Most helpful comment

find this code:

if (!$this.data('content')) { // Prepend any icon and append any subtext to the main text. text = icon + '<span class="text">' + text + subtext + '</span>'; }

and replace it with:

if ($this.data('thumbnail')) { // Prepare thumbnail text = '<span class="media">' + '<span class="media-left"><img src="' + $this.data('thumbnail') + '" class="media-object" onerror="src=\'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\'"></span>' + '<span class="media-body">' + text + '</span>' + '</span>'; } else if (!$this.data('content')) { // Prepend any icon and append any subtext to the main text. text = icon + '<span class="text">' + text + subtext + '</span>'; }

usage:

<select title="Select your surfboard" class="selectpicker"> <option>Select...</option> <option data-thumbnail="images/icon-chrome.png">Chrome</option> <option data-thumbnail="images/icon-firefox.png">Firefox</option> <option data-thumbnail="images/icon-ie.png">IE</option> <option data-thumbnail="images/icon-opera.png">Opera</option> <option data-thumbnail="images/icon-safari.png">Safari</option> </select>

All 5 comments

Any ideas? I didn't like use data-content... Maybe know another solution?

I am looking for the same solution. Any one have ideas?

Mee too

Any particular reason you don't want to use data-content?

find this code:

if (!$this.data('content')) { // Prepend any icon and append any subtext to the main text. text = icon + '<span class="text">' + text + subtext + '</span>'; }

and replace it with:

if ($this.data('thumbnail')) { // Prepare thumbnail text = '<span class="media">' + '<span class="media-left"><img src="' + $this.data('thumbnail') + '" class="media-object" onerror="src=\'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\'"></span>' + '<span class="media-body">' + text + '</span>' + '</span>'; } else if (!$this.data('content')) { // Prepend any icon and append any subtext to the main text. text = icon + '<span class="text">' + text + subtext + '</span>'; }

usage:

<select title="Select your surfboard" class="selectpicker"> <option>Select...</option> <option data-thumbnail="images/icon-chrome.png">Chrome</option> <option data-thumbnail="images/icon-firefox.png">Firefox</option> <option data-thumbnail="images/icon-ie.png">IE</option> <option data-thumbnail="images/icon-opera.png">Opera</option> <option data-thumbnail="images/icon-safari.png">Safari</option> </select>

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Godrules500 picture Godrules500  路  4Comments

spyhunter88 picture spyhunter88  路  4Comments

Cruyjun picture Cruyjun  路  3Comments

DjSunrise picture DjSunrise  路  3Comments

neuropass picture neuropass  路  3Comments