Question: How to do validation?
See original GitHub issueIf I have a textbox that needs parsing to an int and I would like that textbox to show errors if the parsing fails this is easy to do with Avalonia proper. One just needs to set the errors property of the textbox.
However ( and forgetting about the lens stuff I’m working on ) How would you handle validation if you had the following complex domain model
However it is tedious to have to reflect the parsing errors into the immutable model tree. In fact the model should not be updated if if the parsing fails. This is a local failure. It feels like I should be able to do something like this in FUNCUI.
```fsharp
type Company = {
id: int
name: string
business: string
employees: Person array
revenue: int32
}
type State {
companies Company array
selectedCompany: int
}
So there are two levels. Let’s say we want to edit the Company.revenue field
and this requires validation. There are two types of validation. 1 easy and 1 hard(er).
The first is validation of the revenue:int32
As this is part of the data model we can just perform some validation during the view function and render some message out.
The second is parsing validation. The user should only be allowed to enter in valid integers and if they don’t then a message should be displayed. However strings that don’t parse to an integer can’t be put in the model and won’t be available on the next render pass. This means there needs to be extra storage for this error data which seems a bit tedious though maybe there is no other way.
Do you have any suggestions on this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Throwing away the error state is the easy thing.
Throwing away the error state is exactly what I did first when building the lens system. But that seemed like cheating. I want my textbox to tell me if I’ve input a pattern that cannot be parsed. I also considered writing a custom control. But that also feels like cheating. So I got the two types of validation working in the simple example. The next experiment is to see how I can use this validating text box along with it’s state and put this into the larger more complex master - detail view. I’m curious as to see what abstractions turn up in the final state model and if it’s still possible to keep business logic state and view state cleanly seperated.
Closing this issue because it appears to be abandoned. Feel free to reopen if needed.