Skip to content

Rate

Rules

Basic Example

js
const rule = {
    type:"rate",
    field:"rate",
    title:"Recommendation Level",
    value:3.5,
    props:{
        count: 10,
    }
}

Props Configuration Examples

Allow Half Star Rating

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Product Rating",
    value:0,
    props:{
        allowHalf: true,
        count: 5,
    }
}

Custom Color

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Service Rating",
    value:0,
    props:{
        count: 5,
        color: "#FF6B6B",
    }
}

Readonly Rating

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Average Rating",
    value:4.5,
    props:{
        readonly: true,
        allowHalf: true,
    }
}

Different Sizes

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Rating",
    value:0,
    props:{
        size: "large",
        count: 5,
    }
}

Events Examples

Handle Rating Changes

js
const rule = {
    type:"rate",
    field:"rating",
    title:"Product Rating",
    value:0,
    props:{
        allowHalf: true,
        count: 5,
    },
    on: {
        'update:value': (value) => {
            console.log('Rating changed:', value);
        },
    },
}

Show Feedback After Rating

js
const rule = [
    {
        type:"rate",
        field:"rating",
        title:"Product Rating",
        value:0,
        props:{
            allowHalf: true,
            count: 5,
        },
        inject: true,
        on: {
            'update:value': ($inject, value) => {
                // Display feedback based on rating
                const feedbackMap = {
                    1: "Very Poor",
                    2: "Poor",
                    3: "Average",
                    4: "Good",
                    5: "Excellent",
                };
                const level = Math.ceil(value);
                $inject.api.setValue('feedback', feedbackMap[level] || '');
            },
        },
    },
    {
        type:"input",
        field:"feedback",
        title:"Feedback",
        props: {
            disabled: true,
        },
    },
]

Complete configuration items: naive-ui_Rate

value :Number

Props

NameTypeDefault ValueDescription
allow-halfbooleanfalseAllow only half icon activation
colorstringundefinedColor of activated icons (supports colors like #FFF, #FFFFFF, yellow, rgb(0, 0, 0))
countnumber5Number of icons
readonlybooleanfalseReadonly, interaction disabled
size'small' | 'medium' | 'large' | number'medium'Icon size

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