mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-02 14:02:46 +02:00
Custom value delimiter
This commit is contained in:
parent
152b4283dc
commit
a247c0c031
|
@ -39,9 +39,7 @@ class Choices {
|
|||
// Retrieve elements
|
||||
this.element = this.options.element;
|
||||
// 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(',') : [];
|
||||
|
||||
console.log(this.valueArray);
|
||||
this.valueArray = this.element.value !== '' ? this.cleanInputValue(this.element.value) : [];
|
||||
|
||||
// Bind methods
|
||||
this.onClick = this.onClick.bind(this);
|
||||
|
@ -51,6 +49,10 @@ class Choices {
|
|||
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
|
||||
* @private
|
||||
|
@ -239,7 +241,9 @@ class Choices {
|
|||
this.valueArray.push(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) {
|
||||
|
@ -248,7 +252,7 @@ class Choices {
|
|||
let index = this.valueArray.indexOf(value);
|
||||
this.valueArray.splice(index, 1);
|
||||
|
||||
this.element.value = this.valueArray.toString();
|
||||
this.element.value = this.valueArray.join(this.options.delimiter);
|
||||
}
|
||||
|
||||
addItem(value) {
|
||||
|
|
Loading…
Reference in a new issue