Editor number field validation based on existing value/accessing current value within validator?

Editor number field validation based on existing value/accessing current value within validator?

yetyet Posts: 43Questions: 17Answers: 1

I have a field which contains a float. The user should be able to update the number within the range of 0 to the current (most recent value). How would you access the most current value of the field within a validator?

Answers

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    You'd need to make a database call to get the current value that is in the database. A custom validator can be created as described here.

    Allan

  • yetyet Posts: 43Questions: 17Answers: 1

    Correct but how do you get the row index of the currently edited row with a validator?
    In my case I am using a preSubmit hook for iterating over all fields and attached validators...this is already working without problem..the question remains about the currently selected row.

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    The third parameter which is sent to the validators is a "host" information object. It is defined here.

    So you could use $host['id'] to get the id of the row being edited. Keep in mind you might also need to check if the row is being created (i.e. no id). Have a look at the source code for the unique validator which uses this sort of database interaction.

    Allan

This discussion has been closed.