Page 1 of 2

Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 10:03 am
by SBarnes
Is there a way to add validation to a custom field on a debtor for instance if the custom field was a phone number where it was required to start with +61 or that the field contained the necessary elements to be an email address?

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 12:44 pm
by pricerc
SBarnes wrote:Is there a way to add validation to a custom field on a debtor for instance if the custom field was a phone number where it was required to start with +61 or that the field contained the necessary elements to be an email address?


yes.

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 12:46 pm
by SBarnes
Which is?

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 12:46 pm
by Scott.Pearce
lol

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 12:47 pm
by Scott.Pearce
I think Mike has an incoming post with some possibilities...

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 12:50 pm
by Mike.Sheen
SBarnes wrote:Is there a way to add validation to a custom field on a debtor for instance if the custom field was a phone number where it was required to start with +61 or that the field contained the necessary elements to be an email address?


You can use the ErrorText property of the grid cell to display an error indicator with a tooltip indicating the problem:

Code: Select all
grid.ActiveSheet.Cells(Row, grid.ActiveSheet.GetColumnFromTag(null, "RemitNo").Index).ErrorText = "This is my error";


You can do this within the PropertyChanged handler of the custom field values collection of the object - you'll just need to iterate the grid row by row to find the right row with the custom field name or id corresponding to the one in the event parameters.

You can then also add a client cancelled exception on the Savestart event of the business logic to cancel saving if any custom field value is not expected / valid.

You could also add edit masks to the grid cell - to force things like numeric only input - but I'm not a huge fan of that approach - I prefer to display an error indicator instead.

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 12:50 pm
by pricerc

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 12:55 pm
by SBarnes
Yeah well when you turn 50 and the short term memory start to go :lol: my bad.

Thanks for the reminder and suggestions.

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 12:57 pm
by pricerc
after reading Douglas Adams, one appreciates the importance of asking the right question....

once or twice a month, I do a pub quiz on a Tuesday night with my brother and sister. About the only time I see them, mostly.

The number of times I've wanted to answer "Yes" to a question like "Was the Queen crowned in 1952 or 1953?".... We'd win most nights :D

Re: Validate Custom Text Field

PostPosted: Fri Aug 07, 2020 1:02 pm
by Mike.Sheen
pricerc wrote:I do a pub quiz on a Tuesday night


I thought smartphones and the internet kills quiz nights... do they hold it in a giant faraday cage?