1
0
Fork 0
mirror of synced 2024-07-09 08:16:34 +12:00

bindable MDTextfield

This commit is contained in:
Michael Shanks 2020-02-21 21:27:55 +00:00
parent 1398a00212
commit b66996b924
2 changed files with 14 additions and 2 deletions

View file

@ -188,6 +188,7 @@
"description": "A Material Design textfield with multiple variants. Can also be converted to a text area / multine text field.",
"props": {
"onChange": "event",
"value": "string",
"label": "string",
"variant": "string",
"disabled": "bool",

View file

@ -45,6 +45,8 @@
export let cols = 40
export let validation = false
export let persistent = false
export let value
export let _bb
let id = `${label}-${variant}`
@ -87,6 +89,13 @@
function focus(event) {
tfInstance.focus()
}
function changed(e) {
if (_bb.isBound(_bb.props.value)) {
_bb.setStateFromBinding(_bb.props.value, e.target.value)
}
_bb.call(onChange, e.target.value)
}
</script>
<!--
@ -108,7 +117,8 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
{placeholder}
{minLength}
{maxLength}
on:change={e => onChange(e.target.value)} />
value={value}
on:change={changed} />
{:else}
{#if renderLeadingIcon}
<Icon {icon} />
@ -122,9 +132,10 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
placeholder={!!label && fullwidth ? label : placeholder}
{minLength}
{maxLength}
value={value}
aria-label={`Textfield ${variant}`}
on:focus={focus}
on:change={e => onChange(e.target.value)} />
on:change={changed} />
{#if renderTrailingIcon}
<Icon {icon} />
{/if}