question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to do validation?

See original GitHub issue

If 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:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bradphelancommented, Mar 28, 2020

Throwing away the error state is the easy thing.

If you don’t need the error in the state one way to do this would be a custom control that basically has a validate function and only fires TextChanged if the new text is valide… or something 😃

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.

0reactions
JordanMarrcommented, Jan 22, 2023

Closing this issue because it appears to be abandoned. Feel free to reopen if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validating a Questionnaire
Generally speaking the first step in validating a survey is to establish face validity. There are two important steps in this process. First...
Read more >
Question validation in surveys
Question validation is a feature that needs respondents to either answer it or consider answering it. It can make the question mandatory to...
Read more >
Response Requirements & Validation
Response requirements & validation are used to alert respondents about questions they may have missed, or they can be used to solicit a...
Read more >
Making a question required - validation
You can use validation to force respondents to answer a question or request that they consider answering a question before they proceed to...
Read more >
Question validation in surveys
Questions validation is nothing but a feature in surveys which makes respondents to either answer the questions or consider answering it. If a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found