淘汰赛验证选择列表值 [英] Knockout validation select list values

查看:58
本文介绍了淘汰赛验证选择列表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个状态选择列表,该数组的第一个值为-",以便用户必须更改它,而不会意外提交表单,默认的第一个输入为"AK".问题在于表单加载后会立即显示请选择另一个值"错误,因为已标记了初始值.

I have a select list for states with the first value of the array being "-" so that the user must change it and not accidentally submit the form with 'AK' being the default first input. The problem is as soon as the form loads the "Please choose another value" error is showing because the initial value is flagged.

<td>State</td><td><select data-bind="options: $root.stateList, optionsText: 'state', optionsValue: 'state', value: selectedState"></select> </td>

这是对应的js

self.selectedState = ko.observable("").extend({ notEqual: "-" });
self.stateList = [{state: "-"},{state: 'AK'}, {state:'AL'}....{state:'WY'}];

是否有更好的方法在列表中具有空白"的第一个值,以便在加载表单后不将其设置为不正确的输入?如果是这样,简单的.extend({ required: true });是否可以处理它的验证?

Is there a better way to have a "blank" first value in the list so that it's not set to an incorrect input as soon as the form loads? If so, does a simple .extend({ required: true }); handle the valdiation for it?

推荐答案

是否有更好的方法在列表中具有空白"的第一个值,以便在加载表单后不将其设置为不正确的输入?

Is there a better way to have a "blank" first value in the list so that it's not set to an incorrect input as soon as the form loads?

是的.

查看 optionsCaption参数.

这篇关于淘汰赛验证选择列表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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