Last post Mar 11, 2020 02:08 PM by bruce (sqlwork.com)
Member
12 Points
37 Posts
Mar 11, 2020 12:28 PM|ranjithmovva|LINK
Hi,
I've a Country radio button : Yes - No
I don't want to validate when I select No.
Below is my ViewModel
[Required(ErrorMessage = "If Yes, you must choose at least one country.")] public IEnumerable<int> SelectedLocations { get; set; }
VIEW
<label>@Html.RadioButtonFor(model => model.Global, true, new { id = "rdbGGTrue", onchange = "OnChangeforGlobal('rdbGGTrue')" }) Yes</label> <label>@Html.RadioButtonFor(model => model.Global, false,new { id = "rdbGGFalse", onchange = "OnChangeforGlobalc('rdbGGFalse')" }) No</label>
<select asp-for="SelectedLocations" asp-items="@(new SelectList(Model.GlobalLoacations,"Id","Name"))" multiple="multiple" class="form-control"></select>
<span asp-validation-for="SelectedLocations" class="text-danger"></span>
All-Star
58204 Points
15668 Posts
Mar 11, 2020 02:08 PM|bruce (sqlwork.com)|LINK
the usual trick is set the ignore setting option of jquery validation to ignore fields with the "ignore" class you need to override unobtrusive configuration with something like:
$("form").data("validator").settings.ignore = ".ignore, :hidden, :disabled";
then its just:
$('#theFiiedId').addClass(".ignore");
note: this will not effect server validation.
Member
12 Points
37 Posts
Remove Model validation using Jquery
Mar 11, 2020 12:28 PM|ranjithmovva|LINK
Hi,
I've a Country radio button : Yes - No
I don't want to validate when I select No.
Below is my ViewModel
[Required(ErrorMessage = "If Yes, you must choose at least one country.")]
public IEnumerable<int> SelectedLocations { get; set; }
VIEW
<label>@Html.RadioButtonFor(model => model.Global, true, new { id = "rdbGGTrue", onchange = "OnChangeforGlobal('rdbGGTrue')" }) Yes</label>
<label>@Html.RadioButtonFor(model => model.Global, false,new { id = "rdbGGFalse", onchange = "OnChangeforGlobalc('rdbGGFalse')" }) No</label>
<select asp-for="SelectedLocations" asp-items="@(new SelectList(Model.GlobalLoacations,"Id","Name"))" multiple="multiple" class="form-control"></select>
<span asp-validation-for="SelectedLocations" class="text-danger"></span>
All-Star
58204 Points
15668 Posts
Re: Remove Model validation using Jquery
Mar 11, 2020 02:08 PM|bruce (sqlwork.com)|LINK
the usual trick is set the ignore setting option of jquery validation to ignore fields with the "ignore" class you need to override unobtrusive configuration with something like:
then its just:
note: this will not effect server validation.