0

I have a JoinStatus field with True or False condition. I also have 2 textboxes named JoiningDate and NotJoiningReason.If user selects checkbox(True Condition) JoiningDate textbox should be validated else (False Condition)NotJoiningReason textbox should be validated.

I am trying to achieve this using Foolproof,but the problem is False Condition is not getting validated.

ViewModel

public bool JoinStatus { get; set; }

[RequiredIf("JoinStatus",true,ErrorMessage="foooooooooooooooo")]
    public DateTime? JoinDate { get; set; }

[RequiredIf("JoinStatus",false, ErrorMessage = "foooooooooooooooo111111111111")]
    public string NotJoiningReason { get; set; }

HTML

 @Html.CheckBoxFor(m => m.JoinStatus, new { @class = "chkbxSwitchReverse", @id = "chkbxJoinStatus", })

@Html.TextBoxFor(m => m.JoinDate,
               new { @class = "form-control", @placeholder = "Specify Month ", @id = "txtJoinDate",@readonly=true, @style = "background-color:white" })

  @Html.TextAreaFor(m => m.NotJoiningReason
                    new { @class = "form-control ", @id = "txtNotJoiningReason", @placeholder = "Not joining reason" })

JavaScript

<script src="~/plugins/foolproofValidation/mvcfoolproof.unobtrusive.min.js"></script>
<script src="~/plugins/foolproofValidation/MvcFoolproofJQueryValidation.min.js"></script>
<script src="~/plugins/foolproofValidation/MvcFoolproofValidation.min.js"></script>
ksg
  • 3,927
  • 7
  • 51
  • 97
  • Have tested this (without the htmlAttributes) and it works fine for me. Not sure why you would have `@readonly = true` (it should be `@readonly = "readonly"`) which would make the textarea not editable and therefore could not be changed if there was a validation error. –  Nov 26 '15 at 12:26
  • `Readonly` condition is not for `textarea` also now i noticed that I am getting `Uncaught ReferenceError: Sys is not defined` on `MvcFoolproofValidation.min.js`.But all condition except the above mentioned scenario is working properly. – ksg Nov 26 '15 at 12:38
  • See if you are getting a 404 in fiddler or dev toolbar when you load the page. Could there be a js file missing? – shahkalpesh Nov 28 '15 at 18:11
  • @shahkalpesh there is no such error like that.I am getting error in one of the lines of `MvcFoolproofValidation.min.js`.Above I have showed how the script is being referenced. – ksg Nov 30 '15 at 05:14

0 Answers0