Note that there are some explanatory texts on larger screens.

plurals
  1. POfubumvc - simple forms validation using IFailureValidationPolicy
    primarykey
    data
    text
    <p>I've been trying to implement form validation correctly and a discussion on fubu mailing list has been the most helpful (<a href="http://groups.google.com/group/fubumvc-devel/browse_thread/thread/d54b135fe0254653/12180cd86e9dc50b" rel="nofollow">http://groups.google.com/group/fubumvc-devel/browse_thread/thread/d54b135fe0254653/12180cd86e9dc50b</a>). I'm still not entirely clear on certain points, I'm a newbie so I'm going through some yak shaving. </p> <p>It seems like the example given in the discussion performed the validation within the controller itself using IsValid(model).</p> <p>I'm trying to avoid this by decorating my input model with validation attributes such as Required and then use the validation configuration to Transfer on failure (via a policy).</p> <pre><code>this.Validation(x =&gt; { x.Actions .Include(call =&gt; call.HasInput &amp;&amp; call.InputType().Name.EndsWith("Input")); x.Failures .ApplyPolicy&lt;AccountValidationFailedPolicy&gt;(); }); </code></pre> <p>And here's the class that implments the policy:</p> <pre><code>public class AccountValidationFailedPolicy : IValidationFailurePolicy { public bool Matches(ValidationFailure context) { return (context.InputType() == typeof (RegisterAccountInput)); } public void Handle(ValidationFailure context) { var incomingRequest = (RegisterAccountInput) context.InputModel; var failedValidation = new RegisterationFailedNotification { CVV = incomingRequest.CVV, AcceptTerms = incomingRequest.AcceptTerms, Countries = incomingRequest.Countries, PhoneNumber = incomingRequest.PhoneNumber, PIN = incomingRequest.PIN }; FubuContinuation.TransferTo(failedValidation); } } </code></pre> <p>Handle simply tries to Transfer to another action via a new model, copying the values into the new model so that I can redisplay them again on the form. </p> <p>I must be doing something wrong here, because it's not transferring anywhere. I have a class with this method which I was hoping would handle it.</p> <p>public AccountViewModel New(RegisterationFailedNotification notification) { .... }</p> <p>Am I on track here, or is there something fundamental that I'm not getting? Perhaps a policy is not the thing to do here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload