Hoppa till innehåll

InputField

Wrapper for input fields.
Automatically prefixes https:// if field type is url.

InputField

PropTypeDescription
idstringInput ID, generated if no property is provided, needed for input label.
Default: generateId()
labelstringField label.
Default: undefined
descriptionstringDescription for the input field, displayed below the input field.
Default: undefined
typestringHTML input field types, e.g., text, textarea, url.
Default: 'text'
namestringName attribute.
Default: undefined
requiredbooleanIf the field is required.
Default: false
disabledbooleanIf the field is disabled.
Default: false
readonlybooleanIf the field is readonly.
Default: false
showbooleanShow and hide the component without re-rendering.
Default: true
maxlengthnumberMax length of input.
Default: undefined
patternstringValidation pattern.
Default: undefined
rowsnumberNumber of rows if textarea.
Default: 3
valuestringUsed if bound to value.
Default: ''
<script>
import { Panel, InputField } from '@soleil-se/config-svelte';
</script>
<Panel heading="Inställningar">
<InputField name="text" label="Text" />
</Panel>
Advanced
<script>
import { Panel, InputField } from '@soleil-se/config-svelte';
import { onSave } from '@soleil-se/config-svelte/utils';
let { values } = $props();
values = {
text: '',
...values
};
onSave(() => values);
</script>
<Panel heading="Inställningar">
<InputField bind:value={values.text} label="Text" />
</Panel>

Default slot after input field.

<InputField name="text" label="Text">
<p class="help-block">Some helpful text</p>
</InputField>

Slot for content in the label element.

<InputField name="text">
{#snippet label()}
Custom <strong>label</strong>
{/snippet}
</InputField>

Slot for content in the description element to be used instead of the prop when HTML formatting is needed.

<InputField name="text">
{#snippet description()}
Custom <strong>description</strong>
{/snippet}
</InputField>

Use the value attribute to set a default value:

<InputField name="text" label="Text" value="Default text" />