Allow Fancy Input validation to be triggered onBlur (#13658)

* Add free_trial to deploy camunda script

* Allow for more validation customisation on fancy input
This commit is contained in:
melohagan 2024-05-10 13:18:30 +01:00 committed by GitHub
parent 58538cc201
commit efaedbccde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 2 deletions

View File

@ -11,6 +11,7 @@
export let error = null export let error = null
export let validate = null export let validate = null
export let suffix = null export let suffix = null
export let validateOn = "change"
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -24,7 +25,16 @@
const newValue = e.target.value const newValue = e.target.value
dispatch("change", newValue) dispatch("change", newValue)
value = newValue value = newValue
if (validate) { if (validate && (error || validateOn === "change")) {
error = validate(newValue)
}
}
const onBlur = e => {
focused = false
const newValue = e.target.value
dispatch("blur", newValue)
if (validate && validateOn === "blur") {
error = validate(newValue) error = validate(newValue)
} }
} }
@ -61,7 +71,7 @@
type={type || "text"} type={type || "text"}
on:input={onChange} on:input={onChange}
on:focus={() => (focused = true)} on:focus={() => (focused = true)}
on:blur={() => (focused = false)} on:blur={onBlur}
class:placeholder class:placeholder
bind:this={ref} bind:this={ref}
/> />