autocomplete with Materialize - text instead of optional image

大兔子大兔子 提交于 2021-01-07 01:24:05

问题


I am using Materialize Autocomplete and I wonder if there is a way to use text instead of "optional image". Why? In case the text is not unique then the user will not know which one to choose. It might happen that the options will be names and there might two people with the same name and surname.

When typing my question I found out that I cannot use duplicate entries in data

    data: {
        "Radek": myself,
        "Radek": some other Radek,
        "Radoslav": 'http://placehold.it/250x250'
    },

js fiddle example


回答1:


When you look at the source you find the following lines relevant for the images:

autocompleteOption.append('<img src="'+ data[key] +'" class="right circle"><span>'+ key +'</span>');

and

var img = $el.find('img');
$el.html("<span>" + beforeMatch + "<span class='highlight'>" + matchText + "</span>" + afterMatch + "</span>");
$el.prepend(img);

This prevents us from using the image-attribute for anything other than images.

We can insert something like this to trick Materialize

"Radoslav": " style="display: none;">Inserted Text <br><span style="display: none` 

but it will just be converted to text resulting in a option equivalent to

"Inserted Text Radoslav": none

So there is sadly nothing to be gained here.

If you are looking to insert a linebreak, however, you can use this answer on How to force Materialize autocomplete text to flow to new line?



来源:https://stackoverflow.com/questions/65520784/autocomplete-with-materialize-text-instead-of-optional-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!