mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-20 22:46:33 +02:00
Ability to disable search
This commit is contained in:
parent
f361e4b34d
commit
7cfe84e9d1
4
assets/scripts/dist/choices.min.js
vendored
4
assets/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -44,6 +44,7 @@ export class Choices {
|
||||||
prependValue: false,
|
prependValue: false,
|
||||||
appendValue: false,
|
appendValue: false,
|
||||||
selectAll: true,
|
selectAll: true,
|
||||||
|
loadingText: 'Loading...',
|
||||||
templates: {},
|
templates: {},
|
||||||
classNames: {
|
classNames: {
|
||||||
containerOuter: 'choices',
|
containerOuter: 'choices',
|
||||||
|
@ -128,7 +129,6 @@ export class Choices {
|
||||||
} else {
|
} else {
|
||||||
console.error('Choices: Incompatible input passed');
|
console.error('Choices: Incompatible input passed');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -400,16 +400,16 @@ export class Choices {
|
||||||
|
|
||||||
const hasShiftKey = e.shiftKey ? true : false;
|
const hasShiftKey = e.shiftKey ? true : false;
|
||||||
|
|
||||||
// If input is not in focus, it ought to be
|
|
||||||
if(this.input !== document.activeElement) {
|
|
||||||
this.input.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.passedElement.type !== 'text' && !this.dropdown.classList.contains(this.options.classNames.activeState)) {
|
if(this.passedElement.type !== 'text' && !this.dropdown.classList.contains(this.options.classNames.activeState)) {
|
||||||
// For select inputs we always want to show the dropdown if it isn't already showing
|
// For select inputs we always want to show the dropdown if it isn't already showing
|
||||||
this.showDropdown();
|
this.showDropdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If input is not in focus, it ought to be
|
||||||
|
if(this.input !== document.activeElement) {
|
||||||
|
this.input.focus();
|
||||||
|
}
|
||||||
|
|
||||||
if(e.target.hasAttribute('data-button')) {
|
if(e.target.hasAttribute('data-button')) {
|
||||||
if(this.options.removeItems && this.options.removeButton) {
|
if(this.options.removeItems && this.options.removeButton) {
|
||||||
const itemId = e.target.parentNode.getAttribute('data-id');
|
const itemId = e.target.parentNode.getAttribute('data-id');
|
||||||
|
@ -470,6 +470,7 @@ export class Choices {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
onPaste(e) {
|
onPaste(e) {
|
||||||
|
if(e.target !== this.input) return;
|
||||||
// Disable pasting into the input if option has been set
|
// Disable pasting into the input if option has been set
|
||||||
if(!this.options.allowPaste) {
|
if(!this.options.allowPaste) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -909,7 +910,7 @@ export class Choices {
|
||||||
*/
|
*/
|
||||||
ajax(fn) {
|
ajax(fn) {
|
||||||
this.containerOuter.classList.add('is-loading');
|
this.containerOuter.classList.add('is-loading');
|
||||||
this.input.placeholder = "Loading...";
|
this.input.placeholder = this.options.loadingText;
|
||||||
|
|
||||||
const callback = (results, value, label) => {
|
const callback = (results, value, label) => {
|
||||||
if(results && results.length) {
|
if(results && results.length) {
|
||||||
|
@ -1056,7 +1057,7 @@ export class Choices {
|
||||||
|
|
||||||
if(this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
|
if(this.passedElement.type === 'select-multiple' || this.passedElement.type === 'text') {
|
||||||
containerInner.appendChild(input);
|
containerInner.appendChild(input);
|
||||||
} else {
|
} else if(this.options.allowSearch) {
|
||||||
dropdown.insertBefore(input, dropdown.firstChild);
|
dropdown.insertBefore(input, dropdown.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@
|
||||||
|
|
||||||
const choices7 = new Choices('#choices-7');
|
const choices7 = new Choices('#choices-7');
|
||||||
|
|
||||||
const choicesAjax = new Choices('#choices-12').ajax((callback) => {
|
const choicesAjax = new Choices('#choices-12', { allowSearch: false }).ajax((callback) => {
|
||||||
fetch('https://api.discogs.com/artists/391170/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
|
fetch('https://api.discogs.com/artists/391170/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
response.json().then(function(data) {
|
response.json().then(function(data) {
|
||||||
|
|
Loading…
Reference in a new issue