Material-table: row field input max length

Created on 17 Sep 2019  路  3Comments  路  Source: mbrn/material-table

Hi,
Is there anyway to use the maxLength input attribute to limit the number of characters that are allowed to a specific field?

Thanks

Most helpful comment

For anyone who looks for it here is how I've achieve it. You will need to import TextField from material-ui

columns: [
                {
                    title: 'Title', field: 'title', editComponent: props => {
                        return (
                            <TextField
                                value={props.value}
                                inputProps={{ maxLength: 24 }}
                            />
                        )
                    }
                }
            ]

All 3 comments

Ok, so I'e figured out how to do this for all input fields by using:

components={{
EditField: props => (
inputProps={{maxLength: 24}}
/>
),
}}

but i'm not sure how to make this work on individual fields

For anyone who looks for it here is how I've achieve it. You will need to import TextField from material-ui

columns: [
                {
                    title: 'Title', field: 'title', editComponent: props => {
                        return (
                            <TextField
                                value={props.value}
                                inputProps={{ maxLength: 24 }}
                            />
                        )
                    }
                }
            ]

Wanted to update this thread. @omriran's solution worked for me only after including the onChange handler:

columns: [
                {
                    title: 'Title', field: 'title', editComponent: props => {
                        return (
                            <TextField
                                value={props.value}
                                inputProps={{ maxLength: 24 }}
                                onChange={(event) => {props.onChange(event.target.value)}
                            />
                        )
                    }
                }
            ]
Was this page helpful?
0 / 5 - 0 ratings