Comments (4)
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.
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.
@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.
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)
- (resolved-delete)
- 3rd-party custom Window : Building fine but not showing at runtime HOT 8
- Best way to implement "Statically-typed view model" approach? HOT 5
- Drop targeting of .NET Core 3.1? HOT 1
- [Scaling] - Lenses and Submodels: MVU antipatterns? HOT 5
- How to force Binding.addValidation upon returning to wpf usercontrol? HOT 3
- WPF Helpers: GetFocusedElement, GetSelectedElement(s), DragDrop, etc. :: A global approach :: HOT 1
- ApplicationAlreadyRunning Exception HOT 4
- How to create static `OneWaySeq` binding? HOT 6
- Static vs Dynamic bindings performance HOT 13
- Throttling particular message type HOT 5
- `HasErrors` property changed must be raised when errors changed HOT 2
- Build fails for Elmish.WPF HOT 4
- "TwoWayT" and "OneWaySeqT" binding not showing (Version 4.0.0-beta-54) HOT 3
- [Statically-Typed VM] - Missing proper documentation (samples/examples/best practices..) HOT 21
- How to get the listviewitem when clicking on its checkbox with Binding.twoWay in subModelSeq? HOT 1
- Boxingless static bindings
- [Bindings] `TwoWaySeq` HOT 4
- Displaying a List of Lists - HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elmish.wpf.