Я выполняю поиск продуктов с помощью ajax. Я хочу, чтобы в моем поле ввода отображалось «Все», пока я не выберу продукт.
Это представление по умолчанию:

Но как только я выбираю продукт, я хочу, чтобы все исчезло и показывался только продукт:

Я поставил вместе codepen, чтобы, надеюсь, дело пошло!
Всем спасибо!
https://codepen.io/saltcod/pen/bGdzoGN
HTML:
All
И JS:
const options = [{ id: 1, text: 'All' }];
const select2Instance = jQuery( '#choices-multiple-default' ).select2( {
placeholder: 'Search products',
ajax: {
url: url,
dataType: 'json',
delay: 250,
data: params => {
return {
//term: params.term // search query
};
},
// Process fetched results
processResults: data => {
if ( data ) {
data.map( item => {
options.push( { id: item.id, text: item.title } );
} );
}
return {
results: options
};
},
cache: true
},
minimumInputLength: 3 // the minimum of symbols to input before perform a search
} );
Подробнее здесь: https://stackoverflow.com/questions/609 ... r-selected
Мобильная версия