How to bypass fields that have required validation to go to next page
-
I want to show required validator when Contract is selected on this toggle.
<label for="exampleNASAControlNumber">Is this a Contract or Solicitation?:</label>
<label class="switch2">
<input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/></label>
The validation should work for this only when contract is selected:
<label for="exampleStartDate" style="position:relative; right:17px;">Contract Start Period:*:</label>
<input class="form-control" id="contractstartdate" name="contractstartdate" runat="server" placeholder="MM/DD/YYYY" type="text" style="width:240px;"/>
and disabled for this validator:
<label for="exampleStartDate" style="position:relative; right:15px;">Solicitation Start Period:*:</label>
<%----%><input class="form-control" id="solicitationstartdate" name="solicitationstartdate" runat="server" placeholder="MM/DD/YYYY" type="text"/>
The reverse of this when Solicitation is selected, the Contract Start Date validator should be disable and the Solicitation Start Date validator is enabled.
-
I want to show required validator when Contract is selected on this toggle.
<label for="exampleNASAControlNumber">Is this a Contract or Solicitation?:</label>
<label class="switch2">
<input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/></label>
The validation should work for this only when contract is selected:
<label for="exampleStartDate" style="position:relative; right:17px;">Contract Start Period:*:</label>
<input class="form-control" id="contractstartdate" name="contractstartdate" runat="server" placeholder="MM/DD/YYYY" type="text" style="width:240px;"/>
and disabled for this validator:
<label for="exampleStartDate" style="position:relative; right:15px;">Solicitation Start Period:*:</label>
<%----%><input class="form-control" id="solicitationstartdate" name="solicitationstartdate" runat="server" placeholder="MM/DD/YYYY" type="text"/>
The reverse of this when Solicitation is selected, the Contract Start Date validator should be disable and the Solicitation Start Date validator is enabled.
I did it using manual validation and jQuery.Validator.js. for MVC I never used the validator for WebForms. But I would remove your validators and go manual. I wrote a jquery script called load_cc_validator and called it when I toggled the form module in jquery. So I wrote the HTML in Razor and manually assigned the values
Card information
@Html.Label("Edit_CC_FirstName", "First name on card", new { @class = "control-label" })
@Html.TextBox("Edit\_CC\_FirstName", "", new { @class = "form-control", data\_val = "true", data\_val\_required = "Card first name required", placeholder = "First name on card" }) @Html.ValidationMessage("Edit\_CC\_FirstName", new { @class = "field-validation-valid", data\_valmsg\_replace = "true" })
@Html.Hidden("Edit_CC_PaymentID")
@Html.Hidden("Edit_CC_Brand")
<button class="btn btn-default btn-lg mobile" type="button" onclick="return editPayment_cancel()">Cancel</button>
<button class="btn checkout pull-right mobile" type="button" onclick="return submit_eCC()">Save</button>submit_eCC is just a $ajax call to the controller to update the database, and has nothing to do with validation. editPayment_cancel just clears the form and hides the form module. Since I'm using $ajax, I set the Submit Form Handler to false to not submit a post back of the form. And then wrote the script and called it. This example reflects the whole module, and would take too much time to condense
function load_eCC_validate() {
var $cC\_form = $("#Edit\_CreditCard"), $cC\_location = $("#Edit\_CC\_LocationName"), $cC\_fName = $("#Edit\_CC\_FirstName"), $cC\_lName = $("#Edit\_CC\_LastName"), $cC\_code = $("#Edit\_CC\_Code"), $cC\_phone = $("#Edit\_CC\_Phone"); $bA\_streetAddress1 = $("#Edit\_CC\_StreetAddress1"), $bA\_city = $("#Edit\_CC\_City"), $bA\_stateCode = $("#Edit\_CC\_StateCode"), $bA\_postalCode = $("#Edit\_CC\_PostalCode"), $bA\_countryCode = $("#Edit\_CC\_CountryCode"); $cC\_form.validate({ errorClass: 'form-control input-validation-error', validClass: 'form-control', errorElement: 'span',
-
I want to show required validator when Contract is selected on this toggle.
<label for="exampleNASAControlNumber">Is this a Contract or Solicitation?:</label>
<label class="switch2">
<input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/></label>
The validation should work for this only when contract is selected:
<label for="exampleStartDate" style="position:relative; right:17px;">Contract Start Period:*:</label>
<input class="form-control" id="contractstartdate" name="contractstartdate" runat="server" placeholder="MM/DD/YYYY" type="text" style="width:240px;"/>
and disabled for this validator:
<label for="exampleStartDate" style="position:relative; right:15px;">Solicitation Start Period:*:</label>
<%----%><input class="form-control" id="solicitationstartdate" name="solicitationstartdate" runat="server" placeholder="MM/DD/YYYY" type="text"/>
The reverse of this when Solicitation is selected, the Contract Start Date validator should be disable and the Solicitation Start Date validator is enabled.
Perhaps Specifying Validation Groups may be what you need? [^]
_______________________________________________________________ Ah don't lean on me man, cause you can't afford the ticket
-
Perhaps Specifying Validation Groups may be what you need? [^]
_______________________________________________________________ Ah don't lean on me man, cause you can't afford the ticket
ValidationGroup won't work. I only have one button on my form.
-
I want to show required validator when Contract is selected on this toggle.
<label for="exampleNASAControlNumber">Is this a Contract or Solicitation?:</label>
<label class="switch2">
<input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/></label>
The validation should work for this only when contract is selected:
<label for="exampleStartDate" style="position:relative; right:17px;">Contract Start Period:*:</label>
<input class="form-control" id="contractstartdate" name="contractstartdate" runat="server" placeholder="MM/DD/YYYY" type="text" style="width:240px;"/>
and disabled for this validator:
<label for="exampleStartDate" style="position:relative; right:15px;">Solicitation Start Period:*:</label>
<%----%><input class="form-control" id="solicitationstartdate" name="solicitationstartdate" runat="server" placeholder="MM/DD/YYYY" type="text"/>
The reverse of this when Solicitation is selected, the Contract Start Date validator should be disable and the Solicitation Start Date validator is enabled.
The WebForms validators don't include conditional validation out of the box. You can write your own conditional validators, or find a library that does it for you. (The only one I've seen is a commercial component, so I wrote my own.) Or, you can use some code to enable or disable the validator[^] based on a condition. Otherwise, you'll have to stick with the CustomValidator[^]: How to: Validate with a Custom Function for ASP.NET Server Controls[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer