I have a form with 2 fields. One is a signature pad, and one is a checkbox. The checkbox is for staff and says something like "signature is on file", and will replace the signature field with a standard stamp. This all works so far. Problem is they want it so that if the box is not checked, then the signature pad must have a signature (not be null/empty). So I need this field to be required only if the checkbox is unchecked.
I wont want to use Jquery because I want to the form field to use an if else statement. If checkbox unchecked
new { @class = "form-control", required="required"})
else if checked not required. Since I don't know how to blend jquery with c# classes I want to avoid jquery. I also want to avoid postback if possible because the application has A LOT of TempData[] and I dont want to have to go back and figure out all the data that was lost after being accessed.
Is there a way?
Here is my form:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
<span class="text-danger">Leave blank if you wish to fill this part out at later date.</span> <br /><br />
<input type="checkbox" name="SignatureOnFile" value="True"> Check this box if the signature is on file.<br>
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.MySignature, "", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.MySignature, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MySignature, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
Aucun commentaire:
Enregistrer un commentaire