-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist multiselect values and hide selected options
- Loading branch information
1 parent
c8e584b
commit 6d68b24
Showing
11 changed files
with
182 additions
and
71 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
52 changes: 46 additions & 6 deletions
52
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,59 @@ | ||
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 _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 | ||
this.hiddenFieldTarget.dataset.displayForMultiselect = this._fullQuery | ||
} else { | ||
this.hiddenFieldTarget.value = value | ||
} | ||
} | ||
|
||
get _hasEmptyFieldValue() { | ||
if (this._isMultiselect) { | ||
return this.hiddenFieldTarget.dataset.valueForMultiselect === "" | ||
} else { | ||
return this.hiddenFieldTarget.value === "" | ||
} | ||
} | ||
|
||
get _hasFieldValue() { | ||
return !this._hasEmptyFieldValue | ||
} | ||
|
||
get _fieldName() { | ||
return this.hiddenFieldTarget.name | ||
} | ||
|
||
set _fieldName(value) { | ||
this.hiddenFieldTarget.name = value | ||
} | ||
} |
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
Oops, something went wrong.