Update javascript - make zip code not required if selected country not US or Canada

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hi,

I'm trying to to update the javascript code with: If the country selected not US or Canada, make Zip Code is not required. In Nopcommerce the Zip Code field is always required.

The javascript code basically fills the StateProvince dropdown select when an option is selected in the Country dropdown select.

Could you please help me to update the code?

Here is the javascript code inside _CreateOrUpdateAddress.cshtml:


<script type="text/javascript">
$(document).ready(function() {
$("#Address_CountryId").change(function() {
var selectedItem = $(this).val();
var ddlStates = $("#Address_StateProvinceId");
$.ajax({
cache: false,
type: "GET",
url: "/Admin/Country/GetStatesByCountryId",
data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
success: function(data) {
ddlStates.html('');
$.each(data, function(id, option) {
ddlStates.append($('<option></option>').val(option.id).html(option.name));
});
},
error: function(xhr, ajaxOptions, thrownError) {
alert('Failed to retrieve states.');
}
});
});
});
</script>

<input id="Address_ZipPostalCodeEnabled" type="hidden" value="True" name="Address.ZipPostalCodeEnabled" data-val-required="'Zip Postal Code Enabled' must not be empty." data-val="true">
<input id="Address_ZipPostalCodeRequired" type="hidden" value="True" name="Address.ZipPostalCodeRequired" data-val-required="'Zip Postal Code Required' must not be empty." data-val="true">

Thanks!
7 years ago
This has to be changed on C# level, because even if you bypass the JS, C# still holds the rule and will invalidate. :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.