|
|
|
@ -1,5 +1,5 @@ |
|
|
|
<script> |
|
|
|
import "@spectrum-css/textfield/dist/index-vars.css" |
|
|
|
import { TextField } from "@budibase/bbui/internal" |
|
|
|
import Field from "./Field.svelte" |
|
|
|
|
|
|
|
export let field |
|
|
|
@ -10,25 +10,6 @@ |
|
|
|
|
|
|
|
let fieldState |
|
|
|
let fieldApi |
|
|
|
let input |
|
|
|
|
|
|
|
const updateValue = value => { |
|
|
|
if (type === "number") { |
|
|
|
const float = parseFloat(value) |
|
|
|
value = isNaN(float) ? null : float |
|
|
|
} |
|
|
|
fieldApi.setValue(value) |
|
|
|
} |
|
|
|
|
|
|
|
const onBlur = event => { |
|
|
|
updateValue(event.target.value) |
|
|
|
} |
|
|
|
|
|
|
|
const updateValueOnEnter = event => { |
|
|
|
if (event.key === "Enter") { |
|
|
|
updateValue(event.target.value) |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
<Field |
|
|
|
@ -39,34 +20,13 @@ |
|
|
|
bind:fieldState |
|
|
|
bind:fieldApi> |
|
|
|
{#if fieldState} |
|
|
|
<div |
|
|
|
class="spectrum-Textfield" |
|
|
|
class:is-invalid={!$fieldState.valid} |
|
|
|
class:is-disabled={$fieldState.disabled}> |
|
|
|
{#if !$fieldState.valid} |
|
|
|
<svg |
|
|
|
class="spectrum-Icon spectrum-Icon--sizeM spectrum-Textfield-validationIcon" |
|
|
|
focusable="false" |
|
|
|
aria-hidden="true"> |
|
|
|
<use xlink:href="#spectrum-icon-18-Alert" /> |
|
|
|
</svg> |
|
|
|
{/if} |
|
|
|
<input |
|
|
|
on:keyup={updateValueOnEnter} |
|
|
|
bind:this={input} |
|
|
|
disabled={$fieldState.disabled} |
|
|
|
id={$fieldState.fieldId} |
|
|
|
value={$fieldState.value || ''} |
|
|
|
placeholder={placeholder || ''} |
|
|
|
on:blur={onBlur} |
|
|
|
{type} |
|
|
|
class="spectrum-Textfield-input" /> |
|
|
|
</div> |
|
|
|
<TextField |
|
|
|
value={$fieldState.value} |
|
|
|
on:change={e => fieldApi.setValue(e.detail)} |
|
|
|
disabled={$fieldState.disabled} |
|
|
|
error={$fieldState.error} |
|
|
|
id={$fieldState.fieldId} |
|
|
|
{placeholder} |
|
|
|
{type} /> |
|
|
|
{/if} |
|
|
|
</Field> |
|
|
|
|
|
|
|
<style> |
|
|
|
.spectrum-Textfield { |
|
|
|
width: 100%; |
|
|
|
} |
|
|
|
</style> |
|
|
|
|