Skip to content

Input ​

Rules ​

Basic Example ​

js
const rule = {
    type:"input",
    title:"Product Name",
    field:"goods_name",
    value:"iphone 7",
    props: {
        type: "text",
    },
    validate:[
        { required: true, message: 'Please enter product name', trigger: 'blur' },
    ],
}

Props Configuration Examples ​

Textarea ​

js
const rule = {
    type:"input",
    title:"Product Description",
    field:"description",
    props: {
        type: "textarea",
        placeholder: "Please enter product description",
        rows: 4,
        autosize: { minRows: 3, maxRows: 6 },
        resize: "vertical",
    },
}

Password Input ​

js
const rule = {
    type:"input",
    title:"Product Description",
    field:"description",
    props: {
        type: "password",
    },
}

Clearable Input ​

js
const rule = {
    type:"input",
    title:"Username",
    field:"username",
    props: {
        placeholder: "Please enter username",
        allowClear: true,
        prefix: "UserOutlined",
    },
}

Show Character Count ​

js
const rule = {
    type:"input",
    title:"Product Description",
    field:"description",
    props: {
        placeholder: "Please enter product description",
        showCount: true,
        maxlength: 200,
    },
}

Prefix and Suffix Labels ​

js
const rule = {
    type:"input",
    title:"Price",
    field:"price",
    props: {
        addonBefore: "¥",
        addonAfter: "Yuan",
        placeholder: "Please enter price",
    },
}

Disabled State ​

js
const rule = {
    type:"input",
    title:"Order Number",
    field:"order_no",
    value:"ORD20240101001",
    props: {
        disabled: 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",
        allowClear: true,
    },
    on: {
        change: (e) => {
            console.log('Input value changed:', e.target.value);
        },
        pressEnter: (e) => {
            console.log('Pressed Enter:', e.target.value);
        },
    },
}
js
const rule = {
    type:"input",
    title:"Search Product",
    field:"keyword",
    props: {
        placeholder: "Please enter product name to search",
        allowClear: true,
        prefix: "SearchOutlined",
    },
    inject: true,
    on: {
        change: ($inject, e) => {
            // Real-time search: trigger search as user types
            const value = e.target.value;
            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 ​

js
const rule = [
    {
        type:"input",
        title:"Product Name",
        field:"goods_name",
        props: {
            placeholder: "Please enter product name",
        },
        inject: true,
        on: {
            change: ($inject, e) => {
                // Auto-generate product code when name changes
                const value = e.target.value;
                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: Ant-design-vue_Input

value :String

Props ​

ParameterDescriptionTypeDefault
addonAfterInput with label, set suffix labelstring|slot
addonBeforeInput with label, set prefix labelstring|slot
allowClearCan click clear icon to delete contentboolean
borderedWhether to have borderbooleantrue
clearIconCustom clear icon (effective when allowClear is true)slot<CloseCircleFilled />
defaultValueDefault content of input boxstring
disabledWhether disabled, default is falsebooleanfalse
idid of input boxstring
maxlengthMaximum lengthnumber
prefixInput with prefix iconstring|slot
showCountWhether to display character countbooleanfalse
statusSet validation status'error' | 'warning'-
sizeControl size. Note: Input box size in standard form is limited to middle. Options: large middle smallstring-
suffixInput with suffix iconstring|slot
typeDeclare input type, same as native input tag's type attribute, see: MDN(Please use <a-textarea /> instead of type="textarea").stringtext

Input Events ​

Event NameDescriptionCallback Parameters
changeCallback when input content changesfunction(e)
pressEnterCallback when pressing Enterfunction(e)

TextArea ​

ParameterDescriptionTypeDefault
allowClearCan click clear icon to delete contentboolean
autosizeAuto-adapt content height, can be set to `truefalseor object:{ minRows: 2, maxRows: 6 }`boolean|object
showCountWhether to display character countbooleanfalse

TextArea Events ​

Event NameDescriptionCallback Parameters
pressEnterCallback when pressing Enterfunction(e)

Other properties of Textarea are consistent with browser's native textarea.

ParameterDescriptionTypeDefault
enterButtonWhether to have confirm button, can be set to button text. This property conflicts with addon.boolean|slotfalse
loadingSearch loadingboolean

Input.Search Events ​

Event NameDescriptionCallback Parameters
searchCallback when clicking search or pressing Enterfunction(value, event)

Other properties are consistent with Input.

Input.Password ​

ParameterDescriptionTypeDefault
visibleWhether password is visiblebooleanfalse
iconRenderCustom toggle buttonslot-
visibilityToggleWhether to show toggle button or control password visibilitybooleantrue

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