下拉字段 - 第一项应为空
在查找列中使用共享点构建并将其设置为必填字段。 SharePoint 自动选择下拉框中的第一项(对最终用户来说有点误导)。
有没有办法让这个下拉框的第一行显示空白或空?
(我对任何解决方案持开放态度。我更喜欢 javascript 类型的解决方案)
Using sharepoint build in lookup column and it set to required field. SharePoint automatically selects the first item in the dropdown box (kinda misleading for the end users).
Is there a way to display blank or Null for the first row of this drop down box?
(I am open to any solution. I prefer javascript type solution)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于选择字段,默认值在列设置中配置。如果填充了“默认值”输入框,请删除该值以便不使用默认值。
编辑
对于查找字段,如果需要,该字段似乎会发生巨大变化。默认情况下,不需要的字段具有“(无)”值。但是,将该字段切换为必填将删除“(无)”值,并自动选择第一个值。
我发现的一件事是,如果您使用 JavaScript 将 null 值添加到下拉列表中,然后尝试按“确定”,您会收到一个错误页面:“发生了意外错误。”作为解决方法,我编写了更多代码来快速验证该字段在提交表单之前是否有值。如果该字段没有值,则会提示用户并取消提交。 (注意:此代码仅附加到“确定”按钮,因此您在编辑 EditForm.aspx 时可能会遇到错误。只需为查找字段选择一个值,您就可以像平常一样进行编辑)
无论如何,进入代码..我认为您需要更改的唯一行是
var fieldTitle = 'Large Lookup Field';
将其更新为您的字段名称。For Choice fields, the default value is configured in the column settings. If the "Default value" input box is populated, delete the value in order to use no default value.
Edit
For Lookup fields, the field seems to change dramatically if it is required. Fields that are NOT required have a "(None)" value by default. However, toggling the field to required will remove the "(None)" value and the first value is selected automatically.
One thing I found, is that if you use JavaScript to add the null value to the dropdown and then try to press OK you get an error page: "An unexpected error has occurred." As a workaround, I wrote some more code to do a quick validation that the field has a value before the form is submitted. If the field has no value, then it will prompt the user and cancel the submit. (Note: this code is only attached to the OK buttons so you may get errors while editing EditForm.aspx.. just choose a value for your lookup field and you'll be able to edit like normal)
Anyways, onto the code... I think the only line you'll need to change is
var fieldTitle = 'Large Lookup Field';
to update it to the name of your field.作为回应 Kit Menke,我对代码做了一些更改,以便它将保留下拉列表的先前值。我已将以下代码行添加到 AddValueToDropdown()....
In response Kit Menke, I've made a few changes to the code so it will persist previous value of the dropdown. I have added the following lines of code to AddValueToDropdown()....
为了改进 Aaronster 的答案:
AddValueToDropdown
可以这样完成:这对于“添加”和“设置属性”是两个不同页面的文档库是必需的。
funcValidate
开头是:所有这些更改都是为了使整个事情能够与文档库一起使用。
To improve on top of Aaronster's answer:
AddValueToDropdown
can be done that way:This is needed for document libraries where "add" and "set properties" are two distinct pages.
And
funcValidate
starts with:All these changes is to make the whole thing work with document libraries.