I believe that’s the default look of that element on mobile (except you probably rounded the corners). I don’t have an android device but my ios display is somewhat similar.
You are using the chosen plugin and I don’t believe there is support for ios and android.
All modern desktop browsers are supported (Firefox, Chrome, Safari and IE9). Legacy support for IE8 is also enabled. Chosen is disabled on iPhone, iPod Touch, and Android mobile devices (more information).
Thanks for this Paul.
I’m a little confused - I don’t think the chosen plugin is the problem cause if I disable it, I still have the same problem. This blog seems to suggest that the dropdown autocomplete works on mobie - what am I missing?
$(document).ready(function() {
$('.js-select').select2({
allowClear: true,
minimumInputLength: 0,
placeholder: "Start typing or scroll to name",
width: '100%'
});
});
This only gives me a scrollable list, but I also need an input box so I can start typing and get a list of autocomplete results. Please could you show me how to add input box. Any help much appreciated.
Thanks Paul,
Yes I need a list, but also need input box to be able to start entering the item and have it autocomplete, so entering w will jump to Wyoming in your list. Would also like this functionality on mobile device.
Thanks for your help
It basically does that already but in a different (better) way.You can start typing in the input and then the closest match will be highlighted and moved to the top of the select so you can select it easily. I think that’s better than autocomplete.
I don’t really know the select2 well enough to know if there are other ways to set it up. I’ve always used it in that format above.
I would be wary of using any non native controls on mobile but in my example you just remove the match media and it will work in those devices. Most devices have their own versions of selects and offer the best method natively so I would be loathe to mess around with them However I can confirm that my new example is working well on ios.
If none of the above is suitable then this may be a question for the JS forum now perhaps?
Apologies Paul,
Didn’t check the “it will work” link. Looks good on desktop and mobile.
I’m finally making progress - it’s been a while!
Thanks, much appreciated.
Hi Paul, Finally have a working select2 list (with this guy’s help), here’s the code I ended up with:
jQuery(document).ready(function($) {
function matchCustom(params, data) {
// If there are no search terms, return all of the data
if ($.trim(params.term) === '') {
return data;
}
// Do not display the item if there is no 'text' property
if (typeof data.text === 'undefined') {
return null;
}
// `params.term` should be the term that is used for searching
// `data.text` is the text that is displayed for the data object
// This sets search to string start and converts (ignores) case
if (data.text.toLowerCase().indexOf(params.term.toLowerCase()) === 0) {
var modifiedData = $.extend({}, data, true);
modifiedData.text += ' (matched)';
// You can return modified objects from here
// This includes matching the `children` how you want in nested data sets
return modifiedData;
}
// Return `null` if the term should not be displayed
return null;
}
$(".js-select2").select2({
matcher: matchCustom
});
});
Thanks for pointing me in the right direction.
How can I go forward if I don’t know which way I’m facing? (Lennon)