feat: #104 Checkboxes / booleans at last! (#620)

This commit is contained in:
James Read 2025-07-19 02:10:41 +01:00 committed by GitHub
parent fcd1879d09
commit e922baa2e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 2 deletions

View File

@ -241,6 +241,31 @@ func mangleInvalidArgumentValues(req *ExecutionRequest) {
if arg.Type == "datetime" {
mangleInvalidDatetimeValues(req, &arg)
}
mangleCheckboxValues(req, &arg)
}
}
func mangleCheckboxValues(req *ExecutionRequest, arg *config.ActionArgument) {
if arg.Type != "checkbox" {
return
}
log.Infof("Checking checkbox values for argument %s in action %s", arg.Name, req.Action.Title)
for i, _ := range arg.Choices {
choice := &arg.Choices[i]
if req.Arguments[arg.Name] == choice.Title {
log.WithFields(log.Fields{
"arg": arg.Name,
"oldValue": req.Arguments[arg.Name],
"newValue": choice.Value,
"actionTitle": req.Action.Title,
}).Infof("Mangled checkbox value")
req.Arguments[arg.Name] = choice.Value
}
}
}

View File

@ -36,6 +36,14 @@ class ArgumentForm extends window.HTMLElement {
const ret = []
for (const arg of this.argInputs) {
if (arg.type === 'checkbox') {
if (arg.checked) {
arg.value = "1"
} else {
arg.value = "0"
}
}
ret.push({
name: arg.name,
value: arg.value
@ -114,7 +122,7 @@ class ArgumentForm extends window.HTMLElement {
createDomInput (arg) {
let domEl = null
if (arg.choices.length > 0) {
if (arg.choices.length > 0 && (arg.type == "select" || arg.type == "")) {
domEl = document.createElement('select')
// select/choice elements don't get an onchange/validation because theoretically
@ -151,6 +159,13 @@ class ArgumentForm extends window.HTMLElement {
domEl = document.createElement('input')
domEl.setAttribute('type', 'datetime-local')
domEl.setAttribute('step', '1')
break
case 'checkbox':
domEl = document.createElement('input')
domEl.setAttribute('type', 'checkbox')
domEl.setAttribute('name', arg.name)
domEl.setAttribute('value', "1")
break
case 'password':
case 'email':
@ -225,7 +240,7 @@ class ArgumentForm extends window.HTMLElement {
const url = new URL(window.location.href)
if (ev.target.type === 'password') {
return;
return
}
// copy the parameter value