剔除下拉列表负载验证?必需的 [英] knockout dropdown validation on load? required

查看:76
本文介绍了剔除下拉列表负载验证?必需的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于这一篇文章,我发现很多文章都无济于事,我需要找出原因和方式.

There are many post on this one which i find not helpful and i need to find out why and how .

我用两个控件下拉菜单和文本框进行了提琴演奏,并使用.extend 我的提琴

I made a fiddle with two controls dropdown and textbox and applied required validation with .extend My fiddle

问题1::当我第一次加载页面时,在下拉菜单旁边但在文本框旁边却收到验证错误?我很困惑为什么.

Question 1 : when i first load my page i get a validation error beside dropdown but not beside textbox ? i am confused why is that .

问题2:好的.它在加载时显示错误消息很尴尬,所以我计划禁用在加载时显示错误消息.添加了此行ko.validation.init({ insertMessages: false });.这样一来,我就摆脱了加载错误消息的显示.但是,当我单击提交"时,我无法在文本框或dropdwon旁边找到错误消息文本.

Question 2 : Ok . its awkward to display a error message on load so i planned to disable error messages display on load . Added this line ko.validation.init({ insertMessages: false }); . By this i got rid of on load error message display . BUT when i click on submit i can't find the error message text beside textbox or dropdwon .

一种方式或其他方式使我无法显示错误文本.

One way or the other dropdown is failing my cause to display error text.

任何可行的方法都值得赞赏.

Any feasible approach is much appreciated .

推荐答案

  1. 如果您订阅了可观察的数据,您会看到country实际上是由ko加载的,而代码不是这种情况(

  1. If you subscribe to your observables, you will see that country is actually set on load by ko, which is not the case for code (demo):

self.Code.subscribe(function () { alert("Codes changed"); });
self.country.subscribe(function () { alert("Country has changed"); });

这是由select的处理方式(我相信options binding的处理方式)引起的,并解释了为什么在country上进行验证.

This is caused by how select is handled (how options binding is handled I believe) and explains why the validation is done on country.

insertMessages: false将隐藏所有消息,然后您需要使用validationMessage binding处理它们.

insertMessages: false will hide all messages, then you need to handle them with the validationMessage binding.

只需删除可观察对象的初始化值(演示):

Simply remove the init value of your observable (demo):

self.Code = ko.observable();
self.country = ko.observable(); // no ""

这篇关于剔除下拉列表负载验证?必需的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆