Submitting form from the new combos
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "label", "item" ]
|
||||
static targets = [ "label", "item", "hiddenField" ]
|
||||
static values = { selectPropertyName: { type: String, default: "aria-checked" } }
|
||||
|
||||
connect() {
|
||||
@@ -16,8 +16,7 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
get #selectedLabel() {
|
||||
const label = this.#selectedItem.querySelector("[data-combobox-label]")
|
||||
return label.dataset.comboboxLabel
|
||||
return this.#selectedItem?.dataset?.comboboxLabel || ""
|
||||
}
|
||||
|
||||
get #selectedItem() {
|
||||
@@ -28,6 +27,7 @@ export default class extends Controller {
|
||||
this.#clearSelection()
|
||||
item.setAttribute(this.selectPropertyNameValue, "true")
|
||||
this.labelTarget.textContent = this.#selectedLabel
|
||||
this.hiddenFieldTarget.value = item.dataset.comboboxValue
|
||||
}
|
||||
|
||||
#clearSelection() {
|
||||
|
||||
Reference in New Issue
Block a user