1👍
✅
This will check if the countryName
is "Other" and if so, it will check if the country_other
and province_other
fields are not empty. If the country is not "Other" it will check if the province
field is not empty. This way, you make sure that country_other
and province_other
fields are filled when user selects "Other" as countryName
and province field is not required in this case, and also if countryName
is not ‘Other’ province field is required.
const isOtherCountry = this.countryName === 'Other';
if (this.postalCode == '' || this.countryName === '' || this.floorRoom == '' || this.newCustomerName == '' || this.streetAddress == '' || this.cityTown == '' || (!isOtherCountry && this.province == '') || (isOtherCountry && (this.country_other == '' || this.province_other == ''))){
// validation failed
} else {
// validation succeeded
}
Source:stackexchange.com