mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-19 14:06:33 +02:00
Custom value delimiter
This commit is contained in:
parent
152b4283dc
commit
a247c0c031
|
@ -39,9 +39,7 @@ class Choices {
|
||||||
// Retrieve elements
|
// Retrieve elements
|
||||||
this.element = this.options.element;
|
this.element = this.options.element;
|
||||||
// If input already has values, parse the array, otherwise create a blank array
|
// If input already has values, parse the array, otherwise create a blank array
|
||||||
this.valueArray = this.element.value !== '' ? this.element.value.replace(/\s/g, '').split(',') : [];
|
this.valueArray = this.element.value !== '' ? this.cleanInputValue(this.element.value) : [];
|
||||||
|
|
||||||
console.log(this.valueArray);
|
|
||||||
|
|
||||||
// Bind methods
|
// Bind methods
|
||||||
this.onClick = this.onClick.bind(this);
|
this.onClick = this.onClick.bind(this);
|
||||||
|
@ -51,6 +49,10 @@ class Choices {
|
||||||
this.onBlur = this.onChange.bind(this);
|
this.onBlur = this.onChange.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanInputValue(value) {
|
||||||
|
return value.replace(/\s/g, '').split(this.options.delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges unspecified amount of objects into new object
|
* Merges unspecified amount of objects into new object
|
||||||
* @private
|
* @private
|
||||||
|
@ -239,7 +241,9 @@ class Choices {
|
||||||
this.valueArray.push(value);
|
this.valueArray.push(value);
|
||||||
|
|
||||||
// Caste array to string and set it as the hidden inputs value
|
// Caste array to string and set it as the hidden inputs value
|
||||||
this.element.value = this.valueArray.toString();
|
this.element.value = this.valueArray.join(this.options.delimiter);
|
||||||
|
|
||||||
|
console.log(this.element.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeInputValue(value) {
|
removeInputValue(value) {
|
||||||
|
@ -248,7 +252,7 @@ class Choices {
|
||||||
let index = this.valueArray.indexOf(value);
|
let index = this.valueArray.indexOf(value);
|
||||||
this.valueArray.splice(index, 1);
|
this.valueArray.splice(index, 1);
|
||||||
|
|
||||||
this.element.value = this.valueArray.toString();
|
this.element.value = this.valueArray.join(this.options.delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
addItem(value) {
|
addItem(value) {
|
||||||
|
|
Loading…
Reference in a new issue