我遇到与described in this question完全相同的问题。但是接受的解决方案并没有解决问题。
这是我的表单元素标记:
<select
class="form-control"
data-bind="options: industries, optionsText: 'description', optionsValue: 'code', optionsCaption: 'Choose...', value: industry_code"
></select>
我的数据如下:
[
{"code":"00","description":"Unclassified","parent":null},
{"code":"01","description":"Amusement\/Arcade","parent":null},
...
];
我正在尝试使用以下代码创建此字段:
self.industry_code.extend({
required: { message: "Please select an industry." }
});
它非常适合选择,更新等,但是当我第一次加载表单时,“请选择一个行业”。消息出现。我的其他淘汰验证代码(对于<input type='text'>
元素)都没有这样做,所以我希望这个代码的行为方式相同。
我确实尝试过上面提到的问题中提到的解决方案(事实上,我已经使用了optionsCaption
绑定)。也许我错过了一步... the answer to the previous question含糊不清到几乎无用的地步。
还有其他人解决了这个问题吗?
答案 0 :(得分:0)
您的问题的解决方案非常简单。首次初始化viewModel时,需要调用此指令
self.Errors.showAllMessages(false)
这将禁用首次加载时的所有错误。希望这会有所帮助。