Skip to content

Input ​

Rules ​

Basic Example ​

js
const rule = {
    type:"input",
    title:"Product Name",
    field:"goods_name",
    value:"iphone 7",
    props: {
        disabled: true,
    }
}

Props Configuration Examples ​

Text Input (text) ​

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

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 },
    }
}

Password Input (password) ​

js
const rule = {
    type:"input",
    title:"Password",
    field:"password",
    props: {
        type: "password",
        placeholder: "Enter password",
        showPasswordOn: "click",
        clearable: true,
    }
}

Clearable Input ​

js
const rule = {
    type:"input",
    title:"Search Keyword",
    field:"keyword",
    props: {
        placeholder: "Enter search keyword",
        clearable: true,
    }
}

Show Character Count ​

js
const rule = {
    type:"input",
    title:"Product Description",
    field:"description",
    props: {
        type: "textarea",
        placeholder: "Enter product description",
        maxlength: 200,
        showCount: 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 ​

Handle Input and Focus Events ​

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

Real-time Search (update:value event) ​

js
const rule = {
    type:"input",
    title:"Search Products",
    field:"keyword",
    props: {
        placeholder: "Enter product name to search",
        clearable: true,
    },
    inject: true,
    on: {
        'update:value': ($inject, value) => {
            // Auto-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 (update:value event) ​

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

Complete configuration items: naive-ui_Input

value :String

Props ​

NameTypeDefault ValueDescriptionVersion
autofocusbooleanfalseWhether to auto focus
autosizeboolean | { minRows?: number, maxRows?: number }falseAuto-resize content height, only effective for type="textarea", can pass object, e.g. { minRows: 1, maxRows: 3 }
clearablebooleanfalseWhether it can be cleared
disabledbooleanfalseWhether disabled
input-propsHTMLInputAttributesundefinedProperties of the input element inside Input component, not effective for pair type, view native properties here. Note: input-props will not override existing properties of the internal input element (except type)
loadingbooleanundefinedWhether to show loading icon, setting to non undefined will occupy space
maxlengthnumberundefinedMaximum input length
minlengthnumberundefinedMinimum input length
pairbooleanfalseWhether to input paired values
passively-activatedbooleanfalseWhether to passively activate input box
placeholderstring | [string, string]undefinedPlaceholder text for input. If pair is true, placeholder is an array
readonlybooleanfalseWhether readonly
roundbooleanfalseWhether input box is rounded
rowsnumber3Number of input rows, effective for type="textarea"
separatorstringundefinedSeparator between paired input boxes
show-countbooleanfalseWhether to show character count
show-password-on'click' | 'mousedown'undefinedWhen to show password
size'small' | 'medium' | 'large''medium'Input size
status'success' | 'warning' | 'error'undefinedValidation status2.25.0
type'text' | 'password' | 'textarea''text'Input type
on-blur() => voidundefinedCallback triggered when input loses focus
on-change(value: string | [string, string]) => voidundefinedCallback triggered when native change event fires
on-clear() => voidundefinedCallback triggered when clicking clear button
on-focus() => voidundefinedCallback triggered when input gains focus
on-input(value: string | [string, string]) => voidundefinedCallback triggered when user inputs
on-update:value(value: string | [string, string]) => voidundefinedCallback triggered when input value changes

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