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 Sam Rose
parent ad57776b7f
commit e8b8e6e8b4
No known key found for this signature in database
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}
/> />