Reputation: 133
I am having an issue with the Requiredfieldvalidator. look at the below image
From the above Pic, When I Click on the Add New button the Red color hilighted div will appear, If I click on Save button, the Building desctiption button is showing an rfv error. It is fine upto here, but. My issue is when I click on the Cancel button and again click on the Add New button. I am still getting that Building description as show in the Image.
<a class="col-md-1 html5buttons" onclick="ToggleProjectAddBuilding(true)" id="Addbuildingsave">Add New</a>
<div class="col-md-8">
<select asp-for="BuildingDescriptionId" class="chosen-select form-control required" asp-items="@(ViewBag.BuildingTypes)">
<option value="">--Select Building Type--</option>
</select>
<span asp-validation-for="BuildingDescriptionId" id="Customererror" class="text-danger"></span>
</div>
<div class="col-md-offset-8 col-md-9">
<button id="btnSavebuilding" type="submit" class="btn btn-w-m btn-primary">Save</button>
<a class="btn btn-w-m btn-warning" onclick="ToggleProjectAddBuilding(false)">Cancel</a>
</div>
below is the Function code which i have tried to do:
function ToggleProjectAddBuilding(toggle) {
if (toggle) {
$('#formBuilding').slideDown();
}
else {
$('#formBuilding').slideUp();
$('#buildingids').val('');
$('#BuildingDescriptionId-error').html('');
//$('.chosen-select').attr('data-rule-required', 'false');
//$('BuildingDescriptionId').find('select option:eq(0)').prop('selected', true);
//$('#BuildingDescriptionId').attr('selected', 'selected');
//$("#BuildingDescriptionId").val($("#BuildingDescriptionId option:first").val());
//$("#BuildingDescriptionId").prop("selectedIndex", 0);
$("#BuildingDescriptionId option:selected").prop("selected", false);
//$('#ProjectBuildingFloors_Id').val(data.ProjectBuildingFloors.Id);
$('#BuildingType').val('');
$('input#basementtrue').iCheck("uncheck");
$('input#basementfalse').iCheck("check");
$('input#isbasementfinishedtrue').iCheck("uncheck");
}
Upvotes: 1
Views: 83
Reputation: 29693
Ok, in your else part, you add this - $('select.chosen-select').removeClass('input-validation-error')
That will do the trick..
Upvotes: 1