多表单条件验证逻辑修改咨询:适配Other与加拿大场景
表单验证条件修改方案
可以通过分场景逻辑判断调整验证条件,最终验证代码如下:
this.postalCode == '' || this.countryName === '' || this.floorRoom == '' || this.newCustomerName == '' || this.streetAddress == '' || this.cityTown == '' || (this.countryName === 'Other' && (this.country_other === '' || this.province_other === '')) || (this.countryName !== 'Other' && this.countryName !== '加拿大' && this.province === '')
逻辑说明:
- 基础必填校验:保留
postalCode、countryName、floorRoom、newCustomerName、streetAddress、cityTown的空值检查,这些字段无论选择哪个国家都必须填写。 - Other国家场景:当
countryName为Other时,新增country_other和province_other的空值检查,同时跳过province字段的校验(该字段已隐藏)。 - 加拿大场景:当
countryName为加拿大时,province、country_other、province_other均无需校验,可留空。 - 其他国家场景:除上述两种情况外,仍需校验
province字段的空值。
内容的提问来源于stack exchange,提问作者saneese
相关产品推荐
相关产品推荐

