Our blazing fast Grid component built with pure JavaScript


Post by kamran812 »

Can we have a column field with numbers only data but need to add validation on it, only positive integers should enter not negative not 0 value.

  
columns : [ { text: 'Quantity', field: 'quantity', type: 'number' }, ],

Post by tasnim »

Hi,

Here is an example of how you achieve it

{
    text  : 'Age',
    field : 'age',
    width : 100,
    editor : {
        type : 'number',
        listeners : {
            action(event) {
                console.log('fire');
                const { value, source : numberField } = event;
                if (value < 1) {
                    numberField.setError('Invalid Input');  
} else { numberField.clearError(); } }, input(event) { const { value, source : numberField } = event; if (value < 1) { numberField.setError('Invalid Input');
} else { numberField.clearError(); } } } } }

Please check docs
https://bryntum.com/products/grid/docs/api/Core/widget/NumberField#events
https://bryntum.com/products/grid/docs/api/Core/widget/NumberField#function-setError
https://bryntum.com/products/grid/docs/api/Core/widget/NumberField#function-clearError

Here is the output

Attachments
chrome_WaVQXLaJE0.gif
chrome_WaVQXLaJE0.gif (81.31 KiB) Viewed 263 times

Post by kamran812 »

thank you Tasnim, it is working!


Post by Animal »

Wouldn't just setting the min on the field be easier?

https://www.bryntum.com/products/grid/docs/api/Core/widget/NumberField#config-min

editor : {
    min : 0
}

Post Reply