Skip to content

Slider

Rules

Basic Example

js
const rule = {
    type:"slider",
    field:"slider",
    title:"Slider",
    value:[0,52],
    props:{
        min: 0,
        max: 100,
        range: true,
    }
}

Props Configuration Examples

Range Selection

js
const rule = {
    type:"slider",
    field:"priceRange",
    title:"Price Range",
    value:[0,100],
    props:{
        min: 0,
        max: 1000,
        range: true,
        step: 10,
    }
}

Show Marks

js
const rule = {
    type:"slider",
    field:"volume",
    title:"Volume",
    value:50,
    props:{
        min: 0,
        max: 100,
        marks: {
            0: 'Mute',
            50: '50%',
            100: 'Max',
        },
    }
}

Show Input Box

js
const rule = {
    type:"slider",
    field:"discount",
    title:"Discount Rate",
    value:0.9,
    props:{
        min: 0,
        max: 1,
        step: 0.01,
        showInput: true,
    }
}

Events Examples

Listen to Changes

js
const rule = {
    type:"slider",
    field:"volume",
    title:"Volume",
    value:50,
    props:{
        min: 0,
        max: 100,
    },
    on: {
        change: (value) => {
            console.log('Slider value changed:', value);
        },
    },
}

Update Display Value

js
const rule = [
    {
        type:"slider",
        field:"discount",
        title:"Discount Rate",
        value:0.9,
        props:{
            min: 0,
            max: 1,
            step: 0.01,
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Real-time display discount percentage
                $inject.api.setValue('discountText', (value * 100).toFixed(0) + '%');
            },
        },
    },
    {
        type:"input",
        field:"discountText",
        title:"Discount",
        props: {
            disabled: true,
        },
    },
]

Complete configuration items: TDesign_Slider

value :Number | Array

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