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>