1
0
Fork 0
mirror of synced 2024-09-06 12:41:24 +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.", "description": "A Material Design textfield with multiple variants. Can also be converted to a text area / multine text field.",
"props": { "props": {
"onChange": "event", "onChange": "event",
"value": "string",
"label": "string", "label": "string",
"variant": "string", "variant": "string",
"disabled": "bool", "disabled": "bool",

View file

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