Skip to content

Input

input

Rule

Basic Example

js
const rule = {
    type:"input",
    title:"Product Name",
    field:"goods_name",
    value:"iphone 7",
    props: {
        placeholder: 'Please enter product name',
        disabled: false,
    }
}

Props Configuration Examples

Single Line Input (text)

js
const rule = {
    type:"input",
    title:"Username",
    field:"username",
    props: {
        placeholder: 'Please enter username',
        clearable: true,
        leftIcon: 'user-o',
    }
}

Multi-line Input (textarea)

js
const rule = {
    type: 'field',
    title: 'Product Introduction',
    field: 'goods_info',
    value: '',
    props: {
        placeholder: 'Please enter product introduction',
        type: 'textarea',
        autosize: true,
        rows: 4,
    }
}

Password Input (password)

js
const rule = {
    type:"input",
    title:"Password",
    field:"password",
    props: {
        type: 'password',
        placeholder: 'Please enter password',
        clearable: true,
    }
}

Number Input (number/digit)

js
const rule = {
    type:"input",
    title:"Phone Number",
    field:"phone",
    props: {
        type: 'digit',
        placeholder: 'Please enter phone number',
        maxlength: 11,
        clearable: true,
    }
}

Clearable Input

js
const rule = {
    type:"input",
    title:"Search Keyword",
    field:"keyword",
    props: {
        placeholder: 'Please enter search keyword',
        clearable: true,
        clearTrigger: 'always',
        leftIcon: 'search',
    }
}

Show Word Count

js
const rule = {
    type: 'field',
    title: 'Product Description',
    field: 'description',
    props: {
        type: 'textarea',
        placeholder: 'Please enter product description',
        maxlength: 200,
        showWordLimit: true,
    }
}

Disabled and Readonly

js
const rule = {
    type:"input",
    title:"Order Number",
    field:"order_no",
    value:"ORD20240101001",
    props: {
        disabled: true,
        // or use readonly: true,
    }
}

Events Examples

Listen to Input Changes and Focus Events

js
const rule = {
    type:"input",
    title:"Search Keyword",
    field:"keyword",
    props: {
        placeholder: 'Please enter search keyword',
        clearable: true,
    },
    on: {
        input: (value) => {
            console.log('Input value changed:', value);
        },
        blur: (event) => {
            console.log('Field lost focus:', event);
        },
        focus: (event) => {
            console.log('Field gained focus:', event);
        },
        clear: (event) => {
            console.log('Input cleared');
        },
    },
}

Real-time Search (input event)

js
const rule = {
    type:"input",
    title:"Search Products",
    field:"keyword",
    props: {
        placeholder: 'Please enter product name to search',
        clearable: true,
        leftIcon: 'search',
    },
    inject: true,
    on: {
        input: ($inject, value) => {
            // Real-time search: trigger search as user types
            if (value && value.length >= 2) {
                // Call search API
                searchProducts(value).then(res => {
                    // Update search results
                    $inject.api.setValue('searchResults', res.data);
                });
            }
        },
    },
}

Linkage Update Other Fields (input event)

js
const rule = [
    {
        type:"input",
        title:"Product Name",
        field:"goods_name",
        props: {
            placeholder: 'Please enter product name',
        },
        inject: true,
        on: {
        input: ($inject, value) => {
            // Auto-generate product code when product name changes
            if (value) {
                const code = 'GD' + value.substring(0, 3).toUpperCase() + Date.now().toString().slice(-6);
                $inject.api.setValue('goods_code', code);
            }
        },
        },
    },
    {
        type:"input",
        title:"Product Code",
        field:"goods_code",
        props: {
            disabled: true,
        },
    },
]

Complete configuration items:Vant_Input

value :String

Props

ParameterDescriptionTypeDefault Value
v-modelCurrent input valuenumber | string-
labelText on the left side of input boxstring-
nameName, used as identifier when submitting formstring-
idInput box id, also sets the for attribute of labelstringvan-field-n-input
typeInput box type, supports all type attributes of native input tag, additionally supports digit typeFieldTypetext
sizeSize, optional values are large normalstring-
maxlengthMaximum number of input charactersnumber | string-
placeholderPlaceholder text for input boxstring-
borderWhether to show inner borderbooleantrue
disabledWhether to disable input boxbooleanfalse
readonlyWhether it is in readonly state, cannot input content in readonly statebooleanfalse
colonWhether to add colon after labelbooleanfalse
requiredWhether to show form required asteriskboolean | 'auto'null
centerWhether to vertically center contentbooleanfalse
clearableWhether to enable clear icon, clicking clear icon will clear input boxbooleanfalse
clear-iconClear icon name or image link, same as Icon component's name attributestringclear
clear-triggerWhen to show clear icon, always means show when input box is not empty, focus means show when input box is focused and not emptyFieldClearTriggerfocus
clickableWhether to enable click feedbackbooleanfalse
is-linkWhether to show right arrow and enable click feedbackbooleanfalse
autofocusWhether to auto focus, iOS system does not support this attributebooleanfalse
show-word-limitWhether to show word count, requires setting maxlength attributebooleanfalse
errorWhether to mark input content in redbooleanfalse
error-messageBottom error message text, not shown when emptystring-
error-message-alignError message text alignment, optional values are center rightFieldTextAlignleft
formatterInput content formatting function(val: string) => string-
format-triggerWhen formatting function is triggered, optional value is onBlurFieldFormatTriggeronChange
arrow-directionArrow direction, optional values are left up downstringright
label-classAdditional class name for left textstring | Array | object-
label-widthLeft text width, default unit is pxnumber | string6.2em
label-alignLeft text alignment, optional values are center right topFieldTextAlignleft
input-alignInput box alignment, optional values are center rightFieldTextAlignleft
autosizeWhether to adapt to content height, only effective for textarea, can pass object, such as { maxHeight: 100, minHeight: 50 }, unit is pxboolean | FieldAutosizeConfigfalse
left-iconLeft icon name or image link, same as Icon component's name attributestring-
right-iconRight icon name or image link, same as Icon component's name attributestring-
icon-prefixIcon class name prefix, same as Icon component's class-prefix attributestringvan-icon

Events

Event NameDescriptionCallback Parameters
focusTriggered when input box gains focusevent: Event
blurTriggered when input box loses focusevent: Event
clearTriggered when clear button is clickedevent: MouseEvent
clickTriggered when component is clickedevent: MouseEvent
clickInputTriggered when input area is clickedevent: MouseEvent
clickLeftIconTriggered when left icon is clickedevent: MouseEvent
clickRightIconTriggered when right icon is clickedevent: MouseEvent
startValidateTriggered when form validation starts-
endValidateTriggered when form validation ends{ status: string, message: string }

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.