0
Follow
0
View

requierd problems for select triggered by javascript

ycwc880924wc 注册会员
2023-02-27 08:34

Conditional statements can be used to disable cow authentication when both cat1 and cat2 are selected.

cat1: function(){
    this.validObj.challenge('cat1', 'cat1') && this.validObj.required();
    this.disableCowValidation();
},
cat2: function(){
    this.validObj.challenge('cat2', 'cat2') && this.validObj.required();
    this.disableCowValidation();
},
cow1: function(){
    if (!this.isCowValidationDisabled()) {
        this.validObj.challenge('cow1', 'cow1') && this.validObj.required();
    }
},
cow2: function(){
    if (!this.isCowValidationDisabled()) {
        this.validObj.challenge('cow2', 'cow2') && this.validObj.required();
    }
},
isCowValidationDisabled: function() {
    return $('#cat1').val() && $('#cat2').val();
},
disableCowValidation: function() {
    if (this.isCowValidationDisabled()) {
        $('#cow1, #cow2').removeAttr('required');
    } else {
        $('#cow1, #cow2').attr('required', 'required');
    }
},

In the validation function of each select, in addition to validating the input, the disableCowValidation method is called.

The

disableCowValidation method determines whether to disable cow authentication. If yes, it removes the required attribute of cow. If not, add the required attribute.

The

isCowValidationDisabled method checks whether cat1 and cat2 have non-null options. If both options are selected, cow authentication needs to be disabled.

dayuxh 注册会员
2023-02-27 08:34
Hello, I am asked to answer the little assistant, your question has been a little partner to help you answer, thank you for your support and attention to have asked to answer!
PS: Q&A VIP annual card [limited time plus: free IT technical books], for details > > > https://vip.csdn.net/askvip?utm_source=1146287632
zhaolala8 注册会员
2023-02-27 08:34
value != '' && cat2.value != '') {//都不为空再执行验证,同时加上required property $('#cow1,#cow2').prop('required',true) valid1.cow1(); valid1.cow2(); } else {//移除required property $('#cow1,#cow2').prop('required', false) } return !v.has_errors(); }; .
< !- - - - - >
daiyuanrui 注册会员
2023-02-27 08:34

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > you can use the following code to disable the cow validation:

cow1: function(){
    var cat1Val = $('#cat1').val();
    var cat2Val = $('#cat2').val();
    if (cat1Val && cat2Val) {
        this.validObj.challenge('cow1', 'cow1');
        this.validObj.required();
    }
},
cow2: function(){
    var cat1Val = $('#cat1').val();
    var cat2Val = $('#cat2').val();
    if (cat1Val && cat2Val) {
        this.validObj.challenge('cow2', 'cow2');
        this.validObj.required();
    }
},

In the validation functions of cow1 and cow2, get the values of cat1 and cat2 first, and if they are not null, then do the validation of cow. If either of them is null, the cow validation is not executed, and the required error message is not fired.

About the Author

Question Info

Publish Time
2023-02-27 08:34
Update Time
2023-02-27 08:34

Related Question

Salesforce LWC编辑器chrome扩展错误

“select/poll on SSL socket, errno: 4”

For循环'索引错误:超出范围',当它肯定没有超出范围时(webscraping bs4)

使用“for”Python时丢失数据

terrraform + AWS ECS,持续部署流程?

如何乘两个数组与指针使用for循环

FormData FileList返回为[对象FileList]

调用CreateRole操作时发生错误(MalformedPolicyDocument):此策略包含无效的Json

有没有办法从组件道具中获得v-for对象值?

使用Cloud CloudFormation创建本地二级索引