RequiredIf - Boolean values

Sep 27, 2010 at 3:01 PM

Just started using Foolproof after finding it while searching for more validators for MVC. As luck would have it, the first validation scenario I needed failed with foolproof on the client side. Server side validation executed correctly, but the client side did not. I was using the RequiredIfTrue and RequiredIfFalse validators, and the problem seems to be how my boolean value in the view model was being rendered in the view.

public class EditModel(){

public string Description { getset; }
public bool IsSystem {get;set;}


In my view I was rendering IsSystem as a hidden field, which gets a value of either True or False (capital T/F). Reviewing the javascript code, I noticed that there is a check made for "true" and "false" with a lower case T/F. Adding in some adidtional OR statements to also look for True/False seems to have fixed this for me. I had the problem with both the MVC and Jquery validation, but only looked at the Foolproof JQuery script. I changed lines 11, 12, and 13 to be:

else if (value1 === true || value1 === false || value1 === "true" || value1 === "false" || value1 === "True" || value1 === "False") {
        if (value1 == "false" || value1 == "False") value1 = false;
        if (value2 == "false" || value2 == "False") value2 = false;
        value1 = !!value1;
        value2 = !!value2;

I re-ran the javascript unit tests, and they all passed, so at least I havn't broken anything. I wanted to get some feedback on if this was a good way to fix this, or if I should be looking at trying to adjust how my model (boolean values) are rendered.

Sep 27, 2010 at 8:12 PM

Salvoz, check out this thread, let me know if this is the same issue and if the referenced change set works for you:

Sep 30, 2010 at 12:09 AM

I saw that thread before I downloaded, so I started with the latest source as of Monday. Steping thru the javascript code in Firebug I skip over the reference javascript because I'm comparing against a hidden field, not a checkbox. As I mentioned in my first thread I was able to get the desired behvior by adding checks for true/false with a capital T and F.


Dec 21, 2010 at 12:01 PM

Excellent, works like a charm for me now.

I put a .ToLowerCase() on values where needed and it works great.