Various fixes and changes based on tester feedback
This commit is contained in:
@@ -28,15 +28,26 @@ export default class OathHammerClassSheet extends OathHammerItemSheet {
|
||||
return context
|
||||
}
|
||||
|
||||
/** @override — collect checkbox sets explicitly so unchecking all works */
|
||||
_prepareSubmitData(event, form, formData) {
|
||||
const data = super._prepareSubmitData(event, form, formData)
|
||||
data["system.armorProficiency"] = Array.from(
|
||||
form.querySelectorAll('input[name="system.armorProficiency"]:checked')
|
||||
).map(el => el.value)
|
||||
data["system.weaponProficiency"] = Array.from(
|
||||
form.querySelectorAll('input[name="system.weaponProficiency"]:checked')
|
||||
).map(el => el.value)
|
||||
return data
|
||||
/** @override */
|
||||
_onRender(context, options) {
|
||||
super._onRender(context, options)
|
||||
// Handle proficiency checkboxes directly — FormDataExtended mishandles
|
||||
// multiple same-named checkboxes, so we intercept the change event,
|
||||
// collect all checked values ourselves, and stop propagation to prevent
|
||||
// the generic submitOnChange handler from clobbering the data.
|
||||
for (const cb of this.element.querySelectorAll('.proficiency-checkboxes input[type="checkbox"]')) {
|
||||
cb.addEventListener("change", this.#onProficiencyChange.bind(this))
|
||||
}
|
||||
}
|
||||
|
||||
async #onProficiencyChange(event) {
|
||||
event.stopPropagation()
|
||||
const root = this.element
|
||||
const armorProficiency = [...root.querySelectorAll('input[name="system.armorProficiency"]:checked')].map(e => e.value)
|
||||
const weaponProficiency = [...root.querySelectorAll('input[name="system.weaponProficiency"]:checked')].map(e => e.value)
|
||||
await this.document.update({
|
||||
"system.armorProficiency": armorProficiency,
|
||||
"system.weaponProficiency": weaponProficiency,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user