SearchForm
A responsive query form with Search, Reset and optional expansion controls. Fields remain registered while collapsed, so validation, reset, external errors and initial-value snapshots include them.
Import
import { HuiSearchForm, HuiFormItem, HuiInput } from '@nscode/handy-ui'
import type { SearchFormExpose } from '@nscode/handy-ui'
Internal state and controlled updates
Omitted expanded starts at false. Passing the prop makes it controlled; undefined displays as false. Collapsing changes field visibility while retaining field values. Omitting the prop, including when only listening for updates, uses internal state that survives unrelated parent renders. A passed prop remains controlled; rejecting an update preserves the parent value. Switching modes reports a development warning. No defaultValue prop is added.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiSearchForm, HuiButton, HuiSpace, HuiInput, HuiFormItem } from '@nscode/handy-ui'
const q1Redraw = ref(0)
const q1Last = ref('No request')
const q1Model = ref(false)
</script>
<template>
<div class="q1-state-demo search-form-q1-demo">
<HuiButton class="q1-redraw" @click="q1Redraw++">Parent redraw {{ q1Redraw }}</HuiButton>
<HuiSpace direction="vertical" fill>
<div>
<p>Omitted prop: internal state</p>
<div class="q1-local">
<HuiSearchForm :collapse-after="1"
><HuiFormItem label="Field one"><HuiInput placeholder="Field one" /></HuiFormItem
><HuiFormItem label="Field two"><HuiInput placeholder="Field two" /></HuiFormItem
></HuiSearchForm>
</div>
</div>
<div>
<p>Update listener only: internal state</p>
<div class="q1-listener">
<HuiSearchForm :collapse-after="1" @update:expanded="q1Last = String($event)"
><HuiFormItem label="Field one"><HuiInput placeholder="Field one" /></HuiFormItem
><HuiFormItem label="Field two"><HuiInput placeholder="Field two" /></HuiFormItem
></HuiSearchForm>
</div>
</div>
<div>
<p>Explicit undefined: controlled</p>
<div class="q1-empty">
<HuiSearchForm :collapse-after="1" :expanded="undefined"
><HuiFormItem label="Field one"><HuiInput placeholder="Field one" /></HuiFormItem
><HuiFormItem label="Field two"><HuiInput placeholder="Field two" /></HuiFormItem
></HuiSearchForm>
</div>
</div>
<div>
<p>Fixed controlled value: parent rejects</p>
<div class="q1-fixed">
<HuiSearchForm
:collapse-after="1"
:expanded="false"
@update:expanded="q1Last = String($event)"
><HuiFormItem label="Field one"><HuiInput placeholder="Field one" /></HuiFormItem
><HuiFormItem label="Field two"><HuiInput placeholder="Field two" /></HuiFormItem
></HuiSearchForm>
</div>
</div>
<div>
<p>Two-way binding</p>
<div class="q1-bound">
<HuiSearchForm :collapse-after="1" v-model:expanded="q1Model"
><HuiFormItem label="Field one"><HuiInput placeholder="Field one" /></HuiFormItem
><HuiFormItem label="Field two"><HuiInput placeholder="Field two" /></HuiFormItem
></HuiSearchForm>
</div>
</div>
<p class="q1-notification">Bound value: {{ q1Model }}; latest request: {{ q1Last }}</p>
</HuiSpace>
</div>
</template>
Basic usage and events
Place FormItem components in the default slot and assign each a prop. Search emits an event without automatically validating. Reset restores each registered field's captured initial value before emitting reset.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiFormItem, HuiInput, HuiSearchForm, HuiSelect, HuiSpace } from '@nscode/handy-ui'
const query = reactive({ name: '', status: 'enabled' })
const options = [
{ label: 'Enabled', value: 'enabled' },
{ label: 'Disabled', value: 'disabled' }
]
const result = ref('Search to display the query')
const search = () => {
result.value = `search: ${JSON.stringify(query)}`
}
const reset = () => {
result.value = `reset: ${JSON.stringify(query)}`
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSearchForm :model="query" @search="search" @reset="reset">
<HuiFormItem label="Name" prop="name"><HuiInput v-model="query.name" /></HuiFormItem>
<HuiFormItem label="Status" prop="status"
><HuiSelect v-model="query.status" :options="options"
/></HuiFormItem>
</HuiSearchForm>
<span>{{ result }}</span>
</HuiSpace>
</template>
Responsive layout, expansion and extra actions
item-min-width controls the minimum field-column width. collapse-after limits visible items while collapsed; zero disables folding. expanded supports v-model:expanded. Collapsed items retain their values. The actions slot adds buttons after Reset and receives the current size.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiButton, HuiFormItem, HuiInput, HuiSearchForm, HuiSpace } from '@nscode/handy-ui'
const expanded = ref(false)
const query = reactive({ name: '', department: '', city: '', note: '' })
const result = ref('Four fields; two shown initially')
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSearchForm
v-model:expanded="expanded"
:model="query"
:collapse-after="2"
:item-min-width="240"
@search="result = JSON.stringify(query)"
>
<HuiFormItem label="Name" prop="name"><HuiInput v-model="query.name" /></HuiFormItem>
<HuiFormItem label="Department" prop="department"
><HuiInput v-model="query.department"
/></HuiFormItem>
<HuiFormItem label="City" prop="city"><HuiInput v-model="query.city" /></HuiFormItem>
<HuiFormItem label="Note" prop="note"><HuiInput v-model="query.note" /></HuiFormItem>
<template #actions="{ size }"
><HuiButton :size="size" @click="result = 'Export requested for the current query'"
>Export</HuiButton
></template
>
</HuiSearchForm>
<HuiSpace
><HuiButton @click="expanded = !expanded">Toggle externally</HuiButton
><span>expanded: {{ expanded }}; {{ result }}</span></HuiSpace
>
</HuiSpace>
</template>
Fields spanning multiple columns
Use HuiFormItem.span for fields that need more width. It uses the same behavior as a Form grid: positive integer spans are clamped to the actual available column count after measurement. Resize the container below; span=2 spans two columns when available and becomes one column in a narrow container. A larger span=8 fills the available row without creating extra columns.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiFormItem, HuiInput, HuiSearchForm, HuiSpace } from '@nscode/handy-ui'
const query = reactive({ name: '', code: '', address: '', notes: '' })
const result = ref('Edit the fields, then search')
</script>
<template>
<HuiSpace direction="vertical" fill>
<div class="resizable-search">
<HuiSearchForm
:model="query"
:item-min-width="200"
label-position="top"
@search="result = JSON.stringify(query)"
>
<HuiFormItem label="Name · span 1" prop="name"
><HuiInput v-model="query.name"
/></HuiFormItem>
<HuiFormItem label="Code · span 1" prop="code"
><HuiInput v-model="query.code"
/></HuiFormItem>
<HuiFormItem label="Address · span 2" prop="address" :span="2"
><HuiInput v-model="query.address"
/></HuiFormItem>
<HuiFormItem label="Notes · span 8, clamped" prop="notes" :span="8"
><HuiInput v-model="query.notes"
/></HuiFormItem>
</HuiSearchForm>
</div>
<span>{{ result }}</span>
</HuiSpace>
</template>
<style scoped>
.resizable-search {
width: 100%;
min-width: 220px;
max-width: 100%;
resize: horizontal;
overflow: auto;
box-sizing: border-box;
padding: var(--hui-spacing-3);
border: var(--hui-border-width) solid var(--hui-border-color);
}
</style>
Existing style="grid-column: span 2" usage remains supported. Prefer the span prop for automatic clamping; an explicit grid-column style can override it. collapseAfter still counts fields rather than occupied grid cells.
Label positions
Labels support left, right, top and float. auto label width aligns visible labels to the widest one; use a fixed width if expansion should not change label alignment.
<script setup lang="ts">
import { reactive } from 'vue'
import { HuiFormItem, HuiInput, HuiSearchForm, HuiSpace } from '@nscode/handy-ui'
import type { FormLabelPosition } from '@nscode/handy-ui'
const positions: FormLabelPosition[] = ['left', 'right', 'top', 'float']
const query = reactive({ name: '', location: '' })
</script>
<template>
<HuiSpace direction="vertical" fill>
<div v-for="position in positions" :key="position">
<p>{{ position }}</p>
<HuiSearchForm :model="query" :label-position="position" label-width="auto">
<HuiFormItem label="Name" prop="name"><HuiInput v-model="query.name" /></HuiFormItem>
<HuiFormItem label="Location" prop="location"
><HuiInput v-model="query.location"
/></HuiFormItem>
</HuiSearchForm>
</div>
</HuiSpace>
</template>
Size
large, default and small affect fields, controls and action buttons. Their default minimum column widths are 300, 260 and 220px. Explicit FormItem or control sizes can override inherited values.
<script setup lang="ts">
import { reactive } from 'vue'
import { HuiFormItem, HuiInput, HuiSearchForm, HuiSpace } from '@nscode/handy-ui'
import type { SearchFormSize } from '@nscode/handy-ui'
const sizes: SearchFormSize[] = ['large', 'default', 'small']
const query = reactive({ name: '' })
</script>
<template>
<HuiSpace direction="vertical" fill>
<div v-for="size in sizes" :key="size">
<p>{{ size }}</p>
<HuiSearchForm :model="query" :size="size"
><HuiFormItem label="Name" prop="name"><HuiInput v-model="query.name" /></HuiFormItem
></HuiSearchForm>
</div>
</HuiSpace>
</template>
Loading and button text
loading disables Search and Enter-based searches, while the fields and Reset remain available. readonly=true disables Reset to protect readonly values. The four text props override locale defaults; empty strings are preserved. show-reset controls the Reset button independently.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiFormItem, HuiInput, HuiSearchForm, HuiSpace, HuiSwitch } from '@nscode/handy-ui'
const query = reactive({ name: '', city: '' })
const loading = ref(false)
const showReset = ref(true)
const result = ref('Click Find or press Enter in a text input')
const search = async () => {
loading.value = true
try {
await new Promise((resolve) => setTimeout(resolve, 600))
result.value = `Fetched: ${JSON.stringify(query)}`
} finally {
loading.value = false
}
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace><span>Show Reset</span><HuiSwitch v-model="showReset" /></HuiSpace>
<HuiSearchForm
:model="query"
:loading="loading"
:show-reset="showReset"
:collapse-after="1"
search-text="Find"
reset-text="Restore"
expand-text="More filters"
collapse-text="Fewer filters"
@search="search"
>
<HuiFormItem label="Name" prop="name"><HuiInput v-model="query.name" /></HuiFormItem>
<HuiFormItem label="City" prop="city"><HuiInput v-model="query.city" /></HuiFormItem>
</HuiSearchForm>
<span>{{ result }}</span>
</HuiSpace>
</template>
Validate before searching
Call validate() from your search handler when query validation is required. The result resolves with valid=false on failure; it does not reject. Hidden collapsed fields are included.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiFormItem, HuiInput, HuiSearchForm, HuiSpace } from '@nscode/handy-ui'
import type { FormRule } from '@nscode/handy-ui'
const searchRef = ref<InstanceType<typeof HuiSearchForm>>()
const query = reactive({ code: '', city: '' })
const rules: Record<string, FormRule[]> = {
code: [{ required: true, message: 'Enter a code', trigger: 'blur' }]
}
const result = ref('A code is required')
const search = async () => {
const validation = await searchRef.value!.validate()
result.value = validation.valid
? `Query accepted: ${query.code}`
: JSON.stringify(validation.errors)
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSearchForm
ref="searchRef"
:model="query"
:rules="rules"
:collapse-after="1"
@search="search"
>
<HuiFormItem label="Code" prop="code"><HuiInput v-model="query.code" /></HuiFormItem>
<HuiFormItem label="City" prop="city"><HuiInput v-model="query.city" /></HuiFormItem>
</HuiSearchForm>
<span>{{ result }}</span>
</HuiSpace>
</template>
Apply server field errors
External value watching exists only while an assigned error is present and stops when it clears. With scrollToError enabled, setErrors() scrolls to the first field receiving a nonempty error in this call, in form order; old errors and cleared entries do not choose the target.
setErrors passes errors to the internal Form. Keys must exactly match FormItem.prop; for example range.min matches only that literal prop. Dot and bracket paths are not normalized for matching. Arrays display only the first entry; an empty string, undefined or an empty array clears the named field. Other fields retain their state.
Value changes clear API errors even without change rules. The next validation, clearValidate() or resetFields() also clears them. A field's explicit error prop has display priority. These APIs do not emit validate events; unmatched fields print development warnings.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import {
HuiButton,
HuiFormItem,
HuiInput,
HuiInputNumber,
HuiSearchForm,
HuiSpace
} from '@nscode/handy-ui'
const searchRef = ref<InstanceType<typeof HuiSearchForm>>()
const query = reactive({ name: 'Alex', range: { min: 1 } })
const result = ref('Apply errors, then edit either field')
const errors = () => {
searchRef.value!.setErrors({
name: ['Name filter is unavailable', 'Only the first message is shown'],
'range.min': 'Minimum is outside the supported range'
})
result.value = 'Server errors applied to exact props'
}
const clear = () => {
searchRef.value!.setErrors({ name: '', 'range.min': undefined })
result.value = 'Named errors cleared'
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace
><HuiButton @click="errors">Apply server errors</HuiButton
><HuiButton @click="clear">Clear named errors</HuiButton></HuiSpace
>
<HuiSearchForm
ref="searchRef"
scroll-to-error
:model="query"
@search="result = JSON.stringify(query)"
>
<HuiFormItem label="Name" prop="name"><HuiInput v-model="query.name" /></HuiFormItem>
<HuiFormItem label="Minimum" prop="range.min"
><HuiInputNumber v-model="query.range.min"
/></HuiFormItem>
</HuiSearchForm>
<span>{{ result }}</span>
</HuiSpace>
</template>
Remember asynchronously loaded defaults
setInitialValues() captures current registered values as the reset snapshot. After fetching defaults, assign them, await nextTick, capture them, then clearValidate() separately if desired. Capturing never changes the model or clears existing errors.
<script setup lang="ts">
import { nextTick, reactive, ref } from 'vue'
import {
HuiButton,
HuiFormItem,
HuiInput,
HuiSearchForm,
HuiSelect,
HuiSpace
} from '@nscode/handy-ui'
const searchRef = ref<InstanceType<typeof HuiSearchForm>>()
const query = reactive({ name: '', status: '' })
const options = [
{ label: 'Ready', value: 'ready' },
{ label: 'Pending', value: 'pending' }
]
const loading = ref(false)
const result = ref('Load defaults, edit the filters, then click Reset')
const load = async () => {
loading.value = true
try {
await new Promise((resolve) => setTimeout(resolve, 400))
Object.assign(query, { name: 'Saved query', status: 'ready' })
await nextTick()
searchRef.value!.setInitialValues()
searchRef.value!.clearValidate()
result.value = 'Reset now restores the loaded defaults'
} finally {
loading.value = false
}
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace
><HuiButton :loading="loading" @click="load">Load saved defaults</HuiButton
><span>{{ result }}</span></HuiSpace
>
<HuiSearchForm
ref="searchRef"
:model="query"
:loading="loading"
@search="result = JSON.stringify(query)"
@reset="result = `Restored: ${JSON.stringify(query)}`"
>
<HuiFormItem label="Name" prop="name"><HuiInput v-model="query.name" /></HuiFormItem>
<HuiFormItem label="Status" prop="status"
><HuiSelect v-model="query.status" :options="options"
/></HuiFormItem>
</HuiSearchForm>
</HuiSpace>
</template>
Supplied snapshots and explicit undefined
setInitialValues(values) reads and deep-copies the registered field values from the supplied object. setInitialValues() with no argument captures current values; setInitialValues(undefined) deliberately records undefined. These forms preserve their argument-count distinction through SearchForm's forwarding method.
Snapshot methods do not modify the current model or validation state. Fields mounted after a snapshot call capture their own values when they mount. Already mounted collapsed fields are included.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiButton, HuiFormItem, HuiInput, HuiSearchForm, HuiSpace } from '@nscode/handy-ui'
const searchRef = ref<InstanceType<typeof HuiSearchForm>>()
const query = reactive<{ name: string | undefined }>({ name: 'Current filter' })
const resetEvents = ref(0)
const result = ref('Capturing a snapshot leaves the input unchanged')
const preset = () => {
searchRef.value!.setInitialValues({ name: 'Preset filter' })
result.value = 'Preset captured; reset to apply it'
}
const empty = () => {
searchRef.value!.setInitialValues(undefined)
result.value = 'Undefined captured; reset to apply it'
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSearchForm ref="searchRef" :model="query" @reset="resetEvents++"
><HuiFormItem label="Name" prop="name"><HuiInput v-model="query.name" /></HuiFormItem
></HuiSearchForm>
<HuiSpace wrap
><HuiButton @click="preset">Capture supplied values</HuiButton
><HuiButton @click="searchRef?.setInitialValues()">Capture current value</HuiButton
><HuiButton @click="empty">Capture undefined</HuiButton
><HuiButton @click="searchRef?.resetFields()">Reset by method</HuiButton></HuiSpace
>
<span
>{{ result }}; current: {{ query.name ?? '(undefined)' }}; reset-button events:
{{ resetEvents }}</span
>
</HuiSpace>
</template>
Readonly values and resetting
readonly is forwarded to the inner Form and disables the built-in Reset button. Search and expansion remain available. Empty readonly fields retain their placeholders. Applications can still call resetFields() through a ref to restore snapshots without emitting reset. Programmatic changes without an existing error create no new readonly errors; changes to fields with an error recheck all rules. FormItem readonly=false re-enables an individual field.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiButton, HuiFormItem, HuiInput, HuiSearchForm, HuiSpace } from '@nscode/handy-ui'
const searchRef = ref<InstanceType<typeof HuiSearchForm>>()
const readonly = ref(true)
const query = reactive({ name: '' })
const resets = ref(0)
const result = ref('Reset is disabled while readonly; fill values and reset by method')
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace>
<HuiButton @click="readonly = !readonly">Readonly: {{ readonly }}</HuiButton>
<HuiButton @click="query.name = 'Fetched filter'">Fill programmatically</HuiButton>
<HuiButton
@click="
searchRef?.resetFields()
result = 'Snapshot restored by method; no reset event'
"
>Call resetFields()</HuiButton
>
</HuiSpace>
<HuiSearchForm
ref="searchRef"
:model="query"
:readonly="readonly"
@reset="
resets++
result = 'Reset button restored values and emitted reset'
"
@search="result = `Search: ${query.name || '(empty)'}`"
>
<HuiFormItem label="Name" prop="name"
><HuiInput v-model="query.name" placeholder="Name may be empty"
/></HuiFormItem>
</HuiSearchForm>
<span>{{ result }}; value: {{ query.name || '(empty)' }}; reset events: {{ resets }}</span>
</HuiSpace>
</template>
Dirty state, validation state and submission
These methods share the internal Form state. Search still emits search without automatic validation. Listen to submit-success or submit-failed and call submit() when validated native submission is wanted.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiSearchForm, HuiFormItem, HuiInput, HuiButton, HuiSpace } from '@nscode/handy-ui'
import type { FormRule } from '@nscode/handy-ui'
const form = ref<InstanceType<typeof HuiSearchForm>>()
const model = reactive({ keyword: '' })
const result = ref('Waiting')
const rules: Record<string, FormRule[]> = {
keyword: [{ required: true, message: 'Enter a keyword' }]
}
const submit = () => {
form.value?.submit()
}
const capture = () => {
form.value?.setInitialValues()
}
const search = () => {
result.value = `Direct search: ${model.keyword}`
}
const success = () => {
result.value = `Validation passed: ${model.keyword}`
}
const failed = () => {
result.value = 'Enter a keyword first'
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSearchForm
ref="form"
:model="model"
:rules="rules"
@search="search"
@submit-success="success"
@submit-failed="failed"
>
<HuiFormItem prop="keyword" label="Keyword" tip="Edits update dirty state">
<HuiInput v-model="model.keyword" />
</HuiFormItem>
</HuiSearchForm>
<HuiSpace>
<HuiButton @click="capture">Capture defaults</HuiButton>
<HuiButton @click="submit">Call submit()</HuiButton>
</HuiSpace>
<p>
Changed: {{ form?.isDirty() ?? false }}; validating: {{ form?.isValidating() ?? false }};
{{ result }}
</p>
</HuiSpace>
</template>
Inherited Column Width and Explicit Props
Set --hui-search-form-item-min-width on the form or any ancestor. Column minimum width uses the explicit itemMinWidth prop first, then the public variable, then the size default: 300px for large, 260px for default, or 220px for small. Numeric props use px, including 0; CSS length strings are preserved.
Small inherits 180px in this example. Large uses its 320px prop even with a 200px public variable on the same root; removing the prop restores 200px, and enabling it restores 320px. A nested default form inherits 120px from its local ancestor. Narrow containers still limit the minimum to their width. Field spans, collapse behavior, and action layout keep their existing rules.
Set the public variable on an ancestor class in a parent <style scoped>; :deep() is unnecessary. Each form resets private defaults and prop overrides, so nested forms do not inherit an outer form's explicit prop. The unused internal Form width bridge is removed; use the SearchForm public variable for its columns.
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { HuiButton, HuiSearchForm, HuiFormItem, HuiInput } from '@nscode/handy-ui'
const inherited = reactive({ name: '', code: '' })
const configured = reactive({ name: '', code: '' })
const nested = reactive({ name: '', code: '' })
const explicit = ref(true)
const queries = ref(0)
</script>
<template>
<div
class="search-form-variables-demo"
style="--hui-search-form-item-min-width:180px;display:flex;flex-direction:column;gap:var(--hui-spacing-4);max-width:900px"
>
<HuiButton class="search-variables-toggle" @click="explicit = !explicit"
>Explicit width: {{ explicit ? '320px' : 'Unset' }}</HuiButton
>
<p>
Small inherits 180px; large uses its 320px prop or its own 200px variable; nested default
inherits 120px.
</p>
<HuiSearchForm
class="search-variables-inherited"
:model="inherited"
size="small"
label-position="top"
@search="queries++"
>
<HuiFormItem label="Name" prop="name"><HuiInput v-model="inherited.name" /></HuiFormItem>
<HuiFormItem label="Code" prop="code"><HuiInput v-model="inherited.code" /></HuiFormItem>
</HuiSearchForm>
<HuiSearchForm
class="search-variables-explicit"
:model="configured"
size="large"
label-position="top"
:item-min-width="explicit ? 320 : undefined"
style="--hui-search-form-item-min-width:200px"
@search="queries++"
>
<HuiFormItem label="Name" prop="name"><HuiInput v-model="configured.name" /></HuiFormItem>
<HuiFormItem label="Code" prop="code"><HuiInput v-model="configured.code" /></HuiFormItem>
</HuiSearchForm>
<div class="search-variables-nested" style="--hui-search-form-item-min-width:120px">
<HuiSearchForm :model="nested" label-position="top" @search="queries++">
<HuiFormItem label="Name" prop="name"><HuiInput v-model="nested.name" /></HuiFormItem>
<HuiFormItem label="Code" prop="code"><HuiInput v-model="nested.code" /></HuiFormItem>
</HuiSearchForm>
</div>
<span class="search-variables-result">Searches: {{ queries }}</span>
</div>
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| model | Record<string, unknown> | — | Query values used by field props |
| rules | Record<string, FormRule[]> | — | Validation rules; searches do not automatically validate |
| labelWidth | string | number | 'auto' | Label width; numbers are pixels |
| labelPosition | 'left' | 'right' | 'top' | 'float' | 'right' | Label placement |
| scrollToError | boolean | false | Scroll after validation failure or a nonempty setErrors assignment |
| readonly | boolean | false | Forward readonly to the inner Form and disable Reset; FormItem false re-enables a field |
| size | 'large' | 'default' | 'small' | ConfigProvider or default | Fields, controls and buttons size |
| itemMinWidth | string | number | 300 / 260 / 220px by size | Responsive minimum column width |
| collapseAfter | number | 0 | Number of fields shown while collapsed; zero disables folding |
| expanded / v-model:expanded | boolean | undefined | Expanded state. Omit it for internal state starting at false; a passed prop is controlled, with undefined displayed as false. |
| loading | boolean | false | Disable Search and Enter-based searching while loading |
| showReset | boolean | true | Display the Reset button |
| searchText | string | Locale Search | Search button text; empty string is preserved |
| resetText | string | Locale Reset | Reset button text; empty string is preserved |
| expandText | string | Locale Expand | Expand button text; empty string is preserved |
| collapseText | string | Locale Collapse | Collapse button text; empty string is preserved |
Events
| Event | Parameters | Description |
|---|---|---|
| search | — | Search clicked, or Enter pressed in a supported text input |
| reset | — | Reset button restored the field values |
| update:expanded | (expanded: boolean) | The expansion control changed state |
| submit-success | (model: Record<string, unknown> | undefined, event: SubmitEvent) | Forwarded from the internal Form after submission validation passes, not after business saving; submit() does not emit search |
| submit-failed | (result: FormValidateResult, event: SubmitEvent) | Forwarded submission-validation failure, respecting scrollToError; the Search button still does not validate automatically |
Slots
| Slot | Scope | Description |
|---|---|---|
| default | — | FormItem fields; span can occupy multiple grid columns |
| actions | { size: SearchFormSize } | Extra buttons after Reset; buttons inherit the current size |
Methods
Field layout uses the shared HuiFormItem API:
| Field prop | Type | Default | Description |
|---|---|---|---|
| span | number | — | Positive integer column span, clamped to the actual available nonzero columns after measurement |
| Method | Signature | Description |
|---|---|---|
| validate | (callback?: FormValidateCallback) => Promise<FormValidateResult> | Validate registered fields, including collapsed ones |
| resetFields | (props?: string | string[]) => void | Restore snapshots and clear validation; does not emit reset |
| clearValidate | (props?: string | string[]) => void | Clear field validation without changing query data |
| setErrors | (errors: Record<string, string | string[] | undefined>) => void | Set errors for exact field props; arrays use their first message |
| setInitialValues | (...values: [Record<string, unknown>?]) => void | Capture current or supplied defaults; explicit undefined differs from no argument |
| isDirty | (props?: string | string[]) => boolean | Compare mounted fields with reset snapshots; reactive in templates/computed values |
| isValidating | (props?: string | string[]) => boolean | Check pending debounce or asynchronous validation |
| submit | () => void | Forward the internal Form native submit chain; does not emit search |
Types
import type {
SearchFormProps,
SearchFormEmits,
SearchFormExpose,
SearchFormSize,
FormRule,
FormValidateResult,
FormValidateCallback
} from '@nscode/handy-ui'
type SearchFormSize = 'large' | 'default' | 'small'
interface SearchFormExpose {
validate: (callback?: FormValidateCallback) => Promise<FormValidateResult>
resetFields: (props?: string | string[]) => void
clearValidate: (props?: string | string[]) => void
setErrors: (errors: Record<string, string | string[] | undefined>) => void
setInitialValues: (...values: [Record<string, unknown>?]) => void
isDirty: (props?: string | string[]) => boolean
isValidating: (props?: string | string[]) => boolean
submit: () => void
}
See Form for validation rule types and individual FormItem methods.