You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多表单条件验证逻辑修改咨询:适配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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 07:55:17