Page 1 of 2

Select options with backgrounds

Posted: Wed Apr 02, 2014 7:43 pm
by Brian Evans

I can't seem to make dropdown menus show backgrounds. What am I doing wrong here? It's practically the same code we use on our website that works fine.

pre

/pre


Select options with backgrounds

Posted: Wed Apr 02, 2014 8:06 pm
by Brian Evans

pre

/pre


Select options with backgrounds

Posted: Wed Apr 02, 2014 8:07 pm
by Brian Evans

tags didn't work.

code
<option value="99" selected="selected" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/99/223/);"></option>

/code


Select options with backgrounds

Posted: Wed Apr 02, 2014 9:32 pm
by Illya Stepanov

Hi Brian - where you added this code?


Select options with backgrounds

Posted: Wed Apr 02, 2014 9:50 pm
by Brian Evans

Dynamic from REST call
code
var fonts = $('[name=font]');
fonts&#46;html('');
$&#46;each(vars&#46;Fonts, function(i, item) {
fonts&#46;append('<option value=' + vars&#46;Fonts&#46;Font&#46;id + '></option>');

Code: Select all

 var option = $('#Settings_font option[value="' + vars&#46;Fonts[i]&#46;Font&#46;id + '"]'); 

var imageUrl = 'http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/'+vars&#46;Fonts&#46;Font&#46;id+'/'+user_id+'/';
option&#46;css('background-image', 'url("' + imageUrl + '")');
});
fonts&#46;selectmenu('refresh');
/code


Select options with backgrounds

Posted: Thu Apr 03, 2014 3:41 am
by Illya Stepanov

At first you need to use native menu. So select should have data-native-menu attribute:
precode
<select data-native-menu="true">/code/pre

See more about jqm select: http://demos.jquerymobile.com/1.2.1/d...

Also you should know that's 'backgound-image' property for the select option is not working on all browsers.

See details here: http://stackoverflow.com/questions/73...

Regards.


Select options with backgrounds

Posted: Thu Apr 03, 2014 9:42 am
by Brian Evans

It does, I just showed how the options are built. Here is the entire menu after it's built.
code

<select name="font" id="Settings_font" dsid="font" data-theme="d" data-inline="false" data-mini="true" data-icon="arrow-d" data-iconpos="right" data-native-menu="false" tabindex="-1" appery-class="Settings_font"><option value="100" data-placeholder="true" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/100/223/);"></option><option value="99" selected="selected" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/99/223/);"></option><option value="134" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/134/223/);"></option><option value="114" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/114/223/);"></option><option value="115" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/115/223/);"></option><option value="121" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/121/223/);"></option><option value="133" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/133/223/);"></option><option value="128" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/128/223/);"></option><option value="131" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/131/223/);"></option><option value="130" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/130/223/);"></option><option value="132" style="background-image: url(http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/132/223/);"></option></select>

/code


Select options with backgrounds

Posted: Thu Apr 03, 2014 12:57 pm
by Brian Evans

Ok, set native to true and see it works in FF. When run on my Android through the IO tester the menu background is all black and CSS for the select menu isn't changing this.

Is this just not going to work within the App?


Select options with backgrounds

Posted: Thu Apr 03, 2014 2:14 pm
by Kateryna Grynko

Hi Brian,

Try this CSS:precode#screenName_mobileselectmenu-menu &#46;ui-btn-active{
background-image:url(http:&#47;&#47;example&#46;com/bg&#46;png);
}/code/preWhere 'screenName' is a page name,
'mobileselectmenu' is a select component name.


Select options with backgrounds

Posted: Thu Apr 03, 2014 2:17 pm
by Brian Evans

Problem is I need the styling done dynamically.

code
var fonts = $('[name=font]');
fonts&#46;html('');
$&#46;each(vars&#46;Fonts, function(i, item) {
fonts&#46;append('<option value=' + vars&#46;Fonts&#46;Font&#46;id + '></option>');

Code: Select all

 var option = $('#Settings_font option[value="' + vars&#46;Fonts[i]&#46;Font&#46;id + '"]'); 

var imageUrl = 'http:&#47;&#47;sandbox&#46;acavano&#46;com/api/commons/dropdownPreview/'+vars&#46;Fonts&#46;Font&#46;id+'/'+user_id+'/';
option&#46;css('background-image', 'url("' + imageUrl + '")');
});
fonts&#46;selectmenu('refresh');
/code