Add on change action to string field

This commit is contained in:
Andrew Kingston 2022-04-14 09:47:27 +01:00
parent e7ca90cd6b
commit 5d2c337d5d
1 changed files with 10 additions and 1 deletions

View File

@ -10,9 +10,17 @@
export let validation
export let defaultValue = ""
export let align
export let onChange
let fieldState
let fieldApi
const handleChange = e => {
fieldApi.setValue(e.detail)
if (onChange) {
onChange({ value: e.detail })
}
}
</script>
<Field
@ -21,6 +29,7 @@
{disabled}
{validation}
{defaultValue}
{onChange}
type={type === "number" ? "number" : "string"}
bind:fieldState
bind:fieldApi
@ -29,7 +38,7 @@
<CoreTextField
updateOnChange={false}
value={fieldState.value}
on:change={e => fieldApi.setValue(e.detail)}
on:change={handleChange}
disabled={fieldState.disabled}
error={fieldState.error}
id={fieldState.fieldId}