How to hide a vanilla button according to form state

亡梦爱人 提交于 2020-01-21 12:24:07

问题


I am trying to hide my SAVE vanilla button according to form state. when the form state != create the vanilla button should not display. I tried different things but nothing works:

  1. I create a function in js that returns true if form is create state

    function isHideState(){
    formstate = Xrm.Page.ui.getFormType();
    if(formstate == formType.create){
    return true;}
    else{
    return false;}
    }
    
  2. I added a disply rule and connected it to my command that relevant to the js function : my rule is : FormStateRule and state: Create

  3. I connected my command to my vanilla button and yet it display even if the form is'nt in create state.

Am I missing something? it's been hours.. guidance someone?

UPDATE: to be more specific - I need the button to be seen only on create mode.


回答1:


Note: Whenever you are customizing the vanilla button (OOB Save button in your case), Make sure to start by right click the button in Ribbon workbench & click customize button/command to “retain” the OOB behavior & add your customizations on top of it.

Change this line

if(formstate = formType.create){

into

if(formstate == formType.create){

Single = is for assignment; double = is for comparison.

Update:

RibbonDiffXml follows/expects this structure in command:

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

There’s no direct property for rules in Button; only command can be linked.

<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"
/>

After 2013, commandbar introduction changed the behavior of Enable rule similar to Display rule. Disabled buttons using Enable rule will hide the button to utilize the space for other buttons in command bar (as there are always limitation like 7 or 9 buttons in command bar unlike Ribbon).

Enabling buttons again will act like show/hide once switched (similar to Display rule). Probably you can follow this blogpost to achieve yours.

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.




回答2:


We do not need to use JavaScript here, instead of Display rule, please use Enable/Disable rule and apply the FormState rule. Please see below image




回答3:


In the ribbon editor, you can add Display and Enable rules. You can check the form type with no code. Look at this video:

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



来源:https://stackoverflow.com/questions/48141180/how-to-hide-a-vanilla-button-according-to-form-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!