GithubHelp home page GithubHelp logo

Comments (4)

awaynemd avatar awaynemd commented on August 16, 2024

In Elmish.WPF I am using the following code:

"Copay" |> Binding.twoWayOpt((fun m ->Some (Copay.value m.Copay)), SetCopay)
> Binding.addValidation(fun m -> match m with
|{Copay = Copay.InvalidCopay d} -> ["Invalid Copay"]
| _ -> []

Where "Copay" is the bound property to WPF and the model defines Copay as:
Copay: Copay.T

module Copay =
type CopayData = { copay: string}
type T =
| ValidCopay of CopayData
| InvalidCopay of CopayData

    let formatMaskTextBox (s:string) = Regex.Replace( s, @"[^0-9.]","")

    let (|IsCopay|_|) (s:string) = if Regex.IsMatch(s,@"^\d{1,3}.\d{1,2}$") then Some (IsCopay s) else None

    // Define the constructor
    let create (ss: string option) = 
        match ss with
        |None -> InvalidCopay {copay = ""}
        |Some s -> match formatMaskTextBox s with
                   | IsCopay  t -> t |> float |> (fun d -> ValidCopay {copay = sprintf"%3.2f" d})  
                   | _ -> InvalidCopay {copay = s}
        

    // Define deconstructors/ unwrap.  Using "dot" notation to decompose the record.
    let value (f:T) = match f with
                      | ValidCopay d -> d.copay
                      | InvalidCopay d -> d.copay  

    let valueOption (f:T) = match f with
                            | ValidCopay d -> Some d.copay
                            | InvalidCopay d -> None

and SetCopay is:
|SetCopay p -> {m with Copay = Copay.create p}, Cmd.ofMsg InvalidatePolicy

All works correctly to validate an input digital payment. However, the "get" of the binding is executed only once before the
validation code reformats the copay. Hence, the wpf display does not show the "reformatted" input.

Is there anyway to force the binding to update AFTER the validation code is run?

Thanks

from elmish.wpf.

marner2 avatar marner2 commented on August 16, 2024

Can you format your question better? I'm not seeing your validation code.

To try to answer the question generally, though, remember that Elmish.WPF utilizes an MVU architecture. The View only updates after an Update is applied to the Model. So any updates to the Model that aren't through an Update message will not be seen by the View until some other Update happens (the binding in this case is the View).

from elmish.wpf.

awaynemd avatar awaynemd commented on August 16, 2024

@marner2 Thank you for your response. I don't see how to reformat the above without copy/paste ? The validation code is being performed with the "match" statement just below the "Copay" binding.

As to your answer, I'm hopeful there is an override (of some sort) that would allow the ".addValidtion" to trigger an update???

from elmish.wpf.

marner2 avatar marner2 commented on August 16, 2024

Binding.addValidation doesn't actually modify the underlying binding. It sets a parallel error object that WPF error templates can read and display (think of it like an extra bit of information attached to the "CoPay" binding). See Data Validation -> Providing Visual Feedback in the WPF docs about Bindings for more information on how that works.

If you're wanting to modify the actual value in the model so that the "CoPay" binding updates, you would need to do that by modifying the model inside the Update function.

from elmish.wpf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.