Skip to content

Input ​

Rules ​

Basic Example ​

js
const rule = {
    type:"input",
    title:"Product Name",
    field:"goods_name",
    value:"iphone 7",
    col:{
    	span:12,
    	labelWidth:150
    },
    props: {
        type: "text",
    },
    validate:[
        { required: true, message: 'Enter goods_name', trigger: 'blur' },
    ],
}

Props Configuration Examples ​

Clearable Input ​

js
const rule = {
    type:"input",
    title:"Username",
    field:"username",
    props: {
        placeholder: "Enter username",
        clearable: true,
        prefixIcon: "User",
        suffixIcon: "Search",
    },
}

Textarea ​

js
const rule = {
    type:"input",
    title:"Product Description",
    field:"description",
    props: {
        type: "textarea",
        placeholder: "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",
    },
}

Disabled and Readonly ​

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

Input Length Limit ​

js
const rule = {
    type:"input",
    title:"Phone Number",
    field:"phone",
    props: {
        placeholder: "Enter 11-digit phone number",
        maxlength: 11,
        minlength: 11,
        clearable: true,
    },
    validate:[
        { required: true, message: 'Enter phone number', trigger: 'blur' },
    ],
}

Events Examples ​

Listen to Input Change and Focus Events ​

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

Real-time Search (change event) ​

js
const rule = {
    type:"input",
    title:"Search Products",
    field:"keyword",
    props: {
        placeholder: "Enter product name to search",
        clearable: true,
        prefixIcon: "Search",
    },
    inject: true,
    on: {
        change: ($inject, value) => {
            // Real-time search: automatically trigger search as you type
            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 (change event) ​

js
const rule = [
    {
        type:"input",
        title:"Product Name",
        field:"goods_name",
        props: {
            placeholder: "Enter product name",
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // When the product name changes, automatically generate the product code
                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,
        },
    },
]

Slots Examples ​

js
const rule = {
    type:"input",
    title:"Website",
    field:"url",
    props: {
        placeholder: "Enter website",
    },
    children: [
        {
            type: 'div',
            slot: 'prefix',
            children: ['https://']
        },
        {
            type: 'div',
            slot: 'suffix',
            children: ['.com']
        },
    ]
}

Complete configuration items: Element_Input

value :String

Props ​

ParameterDescriptionTypeOptional ValuesDefault Value
typeTypestringtext, textarea and other native input type valuestext
maxlengthNative attribute, maximum input lengthnumber——
minlengthNative attribute, minimum input lengthnumber——
placeholderInput placeholder textstring——
clearableWhether it can be clearedboolean—false
disabledDisabledboolean—false
sizeInput size, only effective when type!="textarea"stringmedium / small / mini—
prefixIconInput header iconstring——
suffixIconInput footer iconstring——
rowsNumber of input rows, only effective for type="textarea"number—2
autosizeAuto-resize content height, only effective for type="textarea", can pass object, e.g., { minRows: 2, maxRows: 6 }boolean / object—false
autocompleteNative attribute, auto-completestringon, offoff
autoCompleteDeprecated in next major versionstringon, offoff
nameNative attributestring——
readonlyNative attribute, whether readonlyboolean—false
maxNative attribute, set maximum value———
minNative attribute, set minimum value———
stepNative attribute, set legal number interval for input field———
resizeControl whether it can be resized by userstringnone, both, horizontal, vertical—
autofocusNative attribute, auto focusbooleantrue, falsefalse
formNative attributestring——
labelLabel text associated with inputstring——
tabindexInput tabindexstring--
validateEventWhether to trigger form validation on inputboolean-true

Events ​

Event NameDescriptionCallback Parameters
blurTriggered when Input loses focus(event: Event)
focusTriggered when Input gains focus(event: Event)
changeTriggered when Input value changes(value: string | number)
clearTriggered when clicking the clear button generated by clearable attribute—

Slots ​

Slot NameDescription
prefixInput header content, only effective for non type="textarea"
suffixInput footer content, only effective for non type="textarea"
prependInput prepend content, only effective for non type="textarea"
appendInput append content, only effective for non type="textarea"

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