如何根据表单状态隐藏香草按钮

How to hide a vanilla button according to form state

我试图根据表单状态隐藏我的保存 vanilla 按钮。当表单状态 != 创建原版按钮时不应显示。我尝试了不同的方法,但没有任何效果:

  1. 我在 js 中创建了一个函数,returns如果表单是创建状态则为真

    function isHideState(){
    formstate = Xrm.Page.ui.getFormType();
    if(formstate == formType.create){
    return true;}
    else{
    return false;}
    }
    
  2. 我添加了一条显示规则并将其连接到与 js 函数相关的命令: 我的规则是:FormStateRule 和状态:Create

  3. 我将我的命令连接到我的香草按钮,但即使表单未处于创建状态,它也会显示。

我错过了什么吗?已经好几个小时了..有人指导吗?

更新:更具体地说 - 我需要按钮仅在创建模式下可见。

注意:每当您自定义香草按钮(在您的情况下为 OOB 保存按钮)时,确保通过右键单击功能区中的按钮开始 workbench &单击 自定义 button/command 以“保留”OOB 行为并在其上添加您的自定义。

更改此行

if(formstate = formType.create){

进入

if(formstate == formType.create){

单=用于赋值; double = 用于比较。

更新:

RibbonDiffXml follows/expects 这个结构在 command:

<CommandDefinition
Id="String">
 <EnableRules />
 <DisplayRules />
 <Actions />
</CommandDefinition>

Button中没有直接的属性规则;只能链接命令。

<Button Alt="String"
  Command="String"
  CommandType=["General" | "OptionSelection" | "IgnoredByMenu" ]
  CommandValueId="String"
  Description="String"
  Id="String"
  Image16by16="String"
  Image16by16Class="String"
  Image16by16Left="Non Positive Integer"
  Image16by16Top="Non Positive Integer"
  Image32by32="String"
  Image32by32Class="String"
  Image32by32Left="String"
  Image32by32Top="String"
  LabelCss="String"
  LabelText="String"
  MenuItemId="String"
  ModernCommandType=[ "ControlCommand"| "System"]
  ModernImage=”String”
  Sequence="1"
  TemplateAlias="String"
  ToolTipDescription="String"
  ToolTipHelpKeyWord="String"
  ToolTipImage32by32="String"
  ToolTipImage32by32Class="String"
  ToolTipImage32by32Left="Non Positive Integer"
  ToolTipImage32by32Top="Non Positive Integer"
  ToolTipShortcutKey="String"
  ToolTipTitle="String"
/>

2013年以后,commandbar的引入改变了Enable规则类似于Display规则的行为。使用启用规则禁用的按钮将隐藏该按钮,以便将 space 用于命令栏中的其他按钮(因为与功能区不同,命令栏中总是有 7 或 9 个按钮之类的限制)。

再次启用按钮将像 show/hide 一旦切换(类似于显示规则)。也许你可以按照这个 blogpost 来实现你的目标。

An important thing to remember is to add the enable rule(s) to the command. This is commonly missed, someone creates an enable rule but forgets to add it to the button command.

If you forget to add enable rules to the command then the button will show on all states/stages of the form. If you forget to add the command to the button, then the button will not show up on the form.

我们这里不需要使用JavaScript,请使用Enable/Disable规则代替Display规则并应用FormState规则。 请看下图

在功能区编辑器中,您可以添加显示和启用规则。您可以在没有代码的情况下检查表单类型。看看这个视频:

https://www.youtube.com/watch?v=xyLzEAW0CJs