feature: Email argument type (#433)

* feature: Email argument type

* bugfix: Fix error if additional links is null
This commit is contained in:
James Read
2024-10-13 19:40:16 +01:00
committed by GitHub
parent 6e0e0e8133
commit b31cdf15a2
3 changed files with 68 additions and 45 deletions

View File

@@ -120,54 +120,61 @@ class ArgumentForm extends window.HTMLElement {
for (const choice of arg.choices) {
domEl.appendChild(this.createSelectOption(choice))
}
} else if (arg.type === 'confirmation') {
this.domBtnStart.disabled = true
domEl = document.createElement('input')
domEl.setAttribute('type', 'checkbox')
domEl.onchange = () => {
this.domBtnStart.disabled = false
domEl.disabled = true
}
} else if (arg.type === 'datetime') {
domEl = document.createElement('input')
domEl.setAttribute('type', 'datetime-local')
domEl.setAttribute('step', '1')
} else if (arg.type === 'password') {
domEl = document.createElement('input')
domEl.setAttribute('type', 'password')
} else {
domEl = document.createElement('input')
switch (arg.type) {
case 'confirmation':
this.domBtnStart.disabled = true
if (arg.type.startsWith('regex:')) {
domEl.setAttribute('pattern', arg.type.replace('regex:', ''))
}
domEl.onchange = () => {
const validateArgumentTypeArgs = {
value: domEl.value,
type: arg.type
}
window.fetch(window.restBaseUrl + 'ValidateArgumentType', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(validateArgumentTypeArgs)
}).then((res) => {
if (res.ok) {
return res.json()
} else {
throw new Error(res.statusText)
domEl = document.createElement('input')
domEl.setAttribute('type', 'checkbox')
domEl.onchange = () => {
this.domBtnStart.disabled = false
domEl.disabled = true
}
}).then((json) => {
if (json.valid) {
domEl.setCustomValidity('')
} else {
domEl.setCustomValidity(json.description)
break
case 'datetime':
domEl = document.createElement('input')
domEl.setAttribute('type', 'datetime-local')
domEl.setAttribute('step', '1')
break
case 'password':
case 'email':
domEl = document.createElement('input')
domEl.setAttribute('type', arg.type)
break
default:
domEl = document.createElement('input')
if (arg.type.startsWith('regex:')) {
domEl.setAttribute('pattern', arg.type.replace('regex:', ''))
}
domEl.onchange = () => {
const validateArgumentTypeArgs = {
value: domEl.value,
type: arg.type
}
window.fetch(window.restBaseUrl + 'ValidateArgumentType', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(validateArgumentTypeArgs)
}).then((res) => {
if (res.ok) {
return res.json()
} else {
throw new Error(res.statusText)
}
}).then((json) => {
if (json.valid) {
domEl.setCustomValidity('')
} else {
domEl.setCustomValidity(json.description)
}
})
}
})
}
}