Cell validation that alters data (byref validator callback)

QuestionsCell validation that alters data (byref validator callback)
Jeremy asked 8 years ago

I have a field that is stored as a float, but presented as a percentage. I'm using the sample code from the docs for formatter and unformat of the cell. It all works well. However, I want to take it a logical step further. Since users see for example "55%", they should be able to enter "55" or "55%" instead of ".55". Obviously if they do that, then the cell value becomes "5500%" and stored in db as 5500.0 – which is no good.

So I would like to add a validation call back that checks if the number is >1 and if so, divides by 100. But instead of passing just the value (which is passed "by value", I need to pass the "Cell" Object. But I don't know the syntax of that. I can't hijack the "formatter" because that is called when the grid is loaded. I need a separate action for when the user edits or adds values.

I have some other situations where this would also be useful. For example, if the user types in "fred smith", I would like to store that in the db as "Fred Smith".

1 Answers
Abu Ghufran answered 8 years ago

Hi,

All such operations and customization can be done in on_update event handler.
You can manipulate the submitted data in php function before saving it in database.

Refer http://phpgrid.org/docs > grid events

Your Answer

9 + 19 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?