How to highlight a wrong field after validate the data ?
First I want to thank you for this contribution to the community that has been very usefu to me.
I was wondering if there is a way to highlight a wrong field (if there is someone) after validate the data when editing a row or adding new one using onRowAdd and onRowUpdate features to show to the user the where is the problem.
I know that i can reject the data using the reject() function of the promise if there are wrong data, but Is there a way to show the user what is the wrong field? either underlined in red or changing the color to the text of the field ?, is there any function to do that?, because I think that sending an alert or putting a message outside the table does not seem like a very elegant way to solve the problem, the ideal solution would be to highlight the wrong field.
Thank you
I think you could implement your own editComponent. On input change validate that input data and do some color stuffs; send signal to parent component and block updates or add
That was precisely what I did, thank you
hi @d1sd41n can you please share your code? i am looking to implement something similar.
Hi karanness86 at this moment unfortunately I no longer have the code that I used to solve that problem, but I will try to explain to you quickly what I did:
Basically I did not use the option that brings table material to edit the table information, what I did was create a totally new component that has nothing to do with materialtable to edit the information in that row. That new component is basically a formon another page which I send the data of the row that I want to edit.
In the table I have created a new edit icon which when clicked calls a function that sends the data of that row to the new edit component.
In that new component I do everything I could not do with materialtable such as validating the information when editing and highlighting the incorrect fields.
Here is a quick example of how the table would be, something like this:
<MaterialTable
title=""
columns={props.tableHead}
data={props.data}
actions={[
{
icon: 'edit',
tooltip: 'Edit this row',
onClick: (event, rowData) => {
sendDatatoEditForm(rowData);
}
}
]}
/>
I wrote the example here, it may have syntax errors
"sendDatatoEditForm(rowData)" It is the function that you have to create to send the data to the new component to be edited.
I hope it helps you bro, greetings.