根据 Sharepoint 2010 中的列值隐藏/禁用编辑按钮

发布于 2024-12-28 18:11:59 字数 126 浏览 1 评论 0原文

我有一列有 2 个类别:“已完成”和“待处理”。一旦用户选择一个项目并且该项目的状态列为“待处理”,我想隐藏/禁用编辑按钮。

我想知道如何做到这一点,无论是在 Visual Studio 2010 还是 ECMA 脚本中。

I have a column that has 2 Categories, Done and Pending. I would like to Hide/Disable edit button once the user selects an item and if that item has a Status column of "Pending".

I would like to know how can this be done, whether in visual studio 2010 or ECMA Scripts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放肆 2025-01-04 18:12:00

我知道这个问题已经很老了,但如果有人仍然需要答案:
在 Visual Studio 中创建自定义操作,如下所示:
https://msdn.microsoft.com/ en-us/library/office/ff408060(v=office.14).aspx

这隐藏了你想要的按钮,现在你可以通过enabledscript参数设置一个条件来选择在哪种情况下按钮应该是隐藏:

只需在 之后添加此代码

<CommandUIHandlers>
        <CommandUIHandler
        Command="HideEditRibbon"
        CommandAction="javascript:return true;" EnabledScript="javascript:checkIfNeedsToBeHidden();" />
</CommandUIHandlers>
<CustomAction Id="yourJsReference" Location="ScriptLink" ScriptSrc="yourJsFile.js"></CustomAction>

如果您在 List-Ribbon、Edit 和 DisplayForm 中需要此代码,则需要制作 3 个自定义操作并更改 Location-Part 以及可能您的 js-代码。

I know this question is old but if someone still needs the answer:
Create a custom action in visual studio like this:
https://msdn.microsoft.com/en-us/library/office/ff408060(v=office.14).aspx

This hides the button you want, now you can set a condition via enabledscript parameter to choose in which case the button should be hidden:

Just add this code after </CommandUIDefinitions>

<CommandUIHandlers>
        <CommandUIHandler
        Command="HideEditRibbon"
        CommandAction="javascript:return true;" EnabledScript="javascript:checkIfNeedsToBeHidden();" />
</CommandUIHandlers>
<CustomAction Id="yourJsReference" Location="ScriptLink" ScriptSrc="yourJsFile.js"></CustomAction>

If you need this in List-Ribbon, Edit and DisplayForm, you need to make 3 Custom Actions and change the Location-Part and maybe your js-code.

复古式 2025-01-04 18:12:00

如果您想使用开箱即用的编辑表单,那么您不会使用服务器端代码来执行此操作;您需要一个完全自定义的编辑表单才能做到这一点。

这意味着在编辑页面上使用 Javascript,这是脆弱的,并且不会阻止用户保存数据(如果他们知道自己在做什么)。

每列的输入字段都有一个带有列名称的“标题”属性。 JQuery 可以很容易地找到 title='column name' 的元素,这样您就可以知道是否需要隐藏保存按钮。保存按钮不太容易到达。您可以尝试使用 type=button 和 value=save 获取输入。

如果对此有实际的安全性很重要,那么无论什么人都无法在此状态下编辑项目,那么您可以在 ItemUpdating 事件上使用事件接收器。只需检查项目的属性并使用properties.Cancel = true; (或类似的东西),这样即使他们禁用你的 JavaScript 并保存事件,它也不会被保存。如果您需要帮助添加事件接收器或使其正常工作,请询问。

编辑:在您的评论中,您说您只是想在某些条件下完全阻止访问编辑表单。为此,我将创建一个新的 Web 部件/用户控件并将其添加到编辑页面。在该部分中,您可以获取适当的项目(该项目的 ID 将是查询参数)并查看页面是否应“可查看”。如果没有,那么您可以重定向到另一个页面。

对上述内容的另一个补充是尝试编辑列表视图,以便某些项目没有编辑链接。这会变得更加困难,而且我怀疑使用开箱即用的 Web 部件是否可能(实际上)实现这一点。您需要有一个完全自定义的列表视图页面,以便控制哪些项目具有指向编辑页面的链接。 (其他人请随时纠正我。)

If you want to use an out of the box edit form then you're not going to do this with server side code; you'd need an entirely custom edit form to do that.

This means using Javascript on the edit page, which is fragile, and doesn't prevent users from saving the data if they know what they're doing.

The input field for every column will have a 'title' attribute with the column name. JQuery can find the element with title='column name' rather easily, so that's how you'll know if you need to hide the save button. The save button isn't quite as easy to get to. You could try getting the input with type=button and value=save.

If it's important to have actual security around this, so that no matter what someone can't edit an item in this state then you can use an event receiver on the ItemUpdating event. Just check the properties of the item and use the properties.Cancel = true; (or something like that) so that even if they disable your JavaScript and save the event anyway, it won't get saved. If you need help adding an event receiver or getting it working just ask.

Edit: In your comment that you say you just want to prevent access to the edit form entirely under certain conditions. For that, I'd make a new webpart/user control and add it to the edit page. In that section you can fetch the appropriate item (the ID of the item will be a query parameter) and see if the page should be 'viewable'. If not, then you can redirect to another page.

Another addition to the above would be attempting to edit the list view such that there is no edit link for certain items. This would be substantially harder, and I doubt it would even be possible (practically) with out of the box webparts. You would need to have an entirely custom list view page in order to control which items have links to an edit page. (Others feel free to correct me here.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文