0

我有一个动态创建的多选,并使用以下代码附加到模板:

                   if(fieldMap[i].required == true){
                        extraString = '<div class="k-edit-label" style="margin-top: -6px;"><label for="'+fieldMap[i].fieldName+'Input">'+fieldMap[i].fieldLabel+'*</label>'+helpText+'</div>\n<div data-container-for="'+fieldMap[i].fieldName+'Input" class="k-edit-field" id="'+fieldMap[i].fieldName+'Container">\n';
                        dynamicComponent = '\t<input class="multiselect-binder" id="'+fieldMap[i].fieldName+'Input" name="'+fieldMap[i].fieldName.toLowerCase()+'" data-auto-close="false" data-role="multiselect" data-bind="value:'+fieldMap[i].fieldName.toLowerCase()+'" required data-required-msg="Please Select Valid '+fieldMap[i].fieldLabel+'" data-source="[';
                        //dynamicComponent = '\t<select id="'+fieldMap[i].fieldName+'Input" data-role="dropdownlist" data-bind="value:'+fieldMap[i].fieldName.toLowerCase()+'" required data-required-msg="Please Select Valid '+fieldMap[i].fieldLabel+'">';
                    } else{
                        extraString = '<div class="k-edit-label" style="margin-top: -6px;"><label for="'+fieldMap[i].fieldName+'Input">'+fieldMap[i].fieldLabel+'</label>'+helpText+'</div>\n<div data-container-for="'+fieldMap[i].fieldName+'Input" class="k-edit-field" id="'+fieldMap[i].fieldName+'Container">\n';
                        dynamicComponent = '\t<input class="multiselect-binder" id="'+fieldMap[i].fieldName+'Input" data-auto-close="false" data-role="multiselect" data-bind="value:'+fieldMap[i].fieldName.toLowerCase()+'" data-source="[';
                        //dynamicComponent = '\t<select id="'+fieldMap[i].fieldName+'Input" data-role="dropdownlist" data-bind="value:'+fieldMap[i].fieldName.toLowerCase()+'">';
                    }
                    optString = '';
                    for(var k = 0; k < fieldMap[i].picklistVals.length; k++){
                        if(k == 0){
                           optString += '\''+fieldMap[i].picklistVals[k]+'\'';   
                        }
                        else{
                            optString += ',\''+fieldMap[i].picklistVals[k]+'\'';   
                        }
                    }
                    //Close the input component as well as the container div
                    dynamicComponent += optString + ']"/>\n<span class="k-invalid-msg" data-for="'+fieldMap[i].fieldName.toLowerCase()+'"></span></div>\n\n';

我在单击保存按钮时运行 validator.validate() 以确定是否应保存信息,这取决于是否需要多选输入。

当没有选择任何内容时,这会弹出无效的工具提示消息。然而,问题是即使做出选择,它也会被标记为无效。我想知道是否有人有任何解决方案来让验证器与多选一起正常工作。仅仅隐藏弹出窗口并不是我真正想要的,因为即使弹出窗口被隐藏,validate() 函数仍然会失败,我需要 validate() 函数才能通过。

4

0 回答 0