-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from jlw/multiple
Add multiple selections mode
- Loading branch information
Showing
50 changed files
with
1,530 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/assets/javascripts/hw_combobox/models/combobox/announcements.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Combobox from "hw_combobox/models/combobox/base" | ||
|
||
Combobox.Announcements = Base => class extends Base { | ||
_announceToScreenReader(display, action) { | ||
this.announcerTarget.innerText = `${display} ${action}` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 61 additions & 6 deletions
67
app/assets/javascripts/hw_combobox/models/combobox/form_field.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,74 @@ | ||
import Combobox from "hw_combobox/models/combobox/base" | ||
|
||
Combobox.FormField = Base => class extends Base { | ||
_setFieldValue(value) { | ||
this.hiddenFieldTarget.value = value | ||
get _fieldValue() { | ||
if (this._isMultiselect) { | ||
const currentValue = this.hiddenFieldTarget.value | ||
const arrayFromValue = currentValue ? currentValue.split(",") : [] | ||
|
||
return new Set(arrayFromValue) | ||
} else { | ||
return this.hiddenFieldTarget.value | ||
} | ||
} | ||
|
||
_setFieldName(value) { | ||
this.hiddenFieldTarget.name = value | ||
get _fieldValueString() { | ||
if (this._isMultiselect) { | ||
return this._fieldValueArray.join(",") | ||
} else { | ||
return this.hiddenFieldTarget.value | ||
} | ||
} | ||
|
||
get _fieldValue() { | ||
return this.hiddenFieldTarget.value | ||
get _incomingFieldValueString() { | ||
if (this._isMultiselect) { | ||
const array = this._fieldValueArray | ||
|
||
if (this.hiddenFieldTarget.dataset.valueForMultiselect) { | ||
array.push(this.hiddenFieldTarget.dataset.valueForMultiselect) | ||
} | ||
|
||
return array.join(",") | ||
} else { | ||
return this.hiddenFieldTarget.value | ||
} | ||
} | ||
|
||
get _fieldValueArray() { | ||
if (this._isMultiselect) { | ||
return Array.from(this._fieldValue) | ||
} else { | ||
return [ this.hiddenFieldTarget.value ] | ||
} | ||
} | ||
|
||
set _fieldValue(value) { | ||
if (this._isMultiselect) { | ||
this.hiddenFieldTarget.dataset.valueForMultiselect = value?.replace(/,/g, "") | ||
this.hiddenFieldTarget.dataset.displayForMultiselect = this._fullQuery | ||
} else { | ||
this.hiddenFieldTarget.value = value | ||
} | ||
} | ||
|
||
get _hasEmptyFieldValue() { | ||
if (this._isMultiselect) { | ||
return this.hiddenFieldTarget.dataset.valueForMultiselect == "" || | ||
this.hiddenFieldTarget.dataset.valueForMultiselect == "undefined" | ||
} else { | ||
return this.hiddenFieldTarget.value === "" | ||
} | ||
} | ||
|
||
get _hasFieldValue() { | ||
return !this._hasEmptyFieldValue | ||
} | ||
|
||
get _fieldName() { | ||
return this.hiddenFieldTarget.name | ||
} | ||
|
||
set _fieldName(value) { | ||
this.hiddenFieldTarget.name = value | ||
} | ||
} |
Oops, something went wrong.