Form buttons and context menus are usually a desirable piece of functionality to include on your form. I have seen scenarios before however, where I needed to limit the options available to a user so that they could really only perform one action. The first options that I would consider in these situations is to simply modify the ‘Condition’ field (for role-specific or other criteria) or the ‘UI Action Visibility’ related list (for view-specific criteria) on the particular UI action that I wanted to remove from the user’s view. This is obviously the best and simplest method since it falls in line with the design of the product and doesn’t really require any unusual override of other system behavior.

Remove Buttons-Roles View
But what if you need to disable something like the ‘Submit’ button on just a single view of a single form? What if you wanted an easy way to disable everything BUT one button based on a change to a particular field? Modifying the UI action condition in these scenarios might not make sense because you don’t want to include a one-off condition for just a single use case or (in the onChange scenario), the UI action conditions are only evaluated on form load so they wouldn’t apply anyway.

This article shows a couple of client script functions that allow you to remove (show/hide) any button (or all but one button)…and, if necessary, disable the form header right-click context menu entirely.

It can’t be emphasized enough that these modifications are not something that you’re going to need to apply on every form in your system. They are really designed for edge cases where there is no other real solution available. If at all possible, you should use the standard ‘Condition’ field (for role-specific or other criteria) or the ‘UI Action Visibility’ related list (for view-specific criteria) on a UI action and stick to the out-of-box functionality in these cases.

Removing a single button

Removing a single button is accomplished by using this code in an ‘onLoad’ or ‘onChange’ client script. The code gets all of the button elements on a form, iterates through them, and remove any button on the form that has ‘Submit’ as the button text. If your UI action has an ‘Action name’ value specified, you could also remove the button by targeting that ID value specifically. I chose this method because it also works on multi-section forms where you may have multiple sets of the same buttons on a form.

//Remove the 'Submit' button
var items = $$('BUTTON').each(function(item){
   if(item.innerHTML.indexOf('Submit') > -1){
      item.hide(); 
   }
});

To only remove the top button and leave the button at the bottom of the form you can simply have your script exit after the first button is hidden like this…

//Remove the top 'Submit' button
var items = $$('BUTTON').each(function(item){
   if(item.innerHTML.indexOf('Submit') > -1){
      item.hide();
      throw $break; //Exit after hiding the first 'Submit' button  
   }
});

Removing all but one button

Removing all but one button can be accomplished in a similar way to the previous example. This example shows one way you could use the button ID value (as defined in the UI action ‘Action name’ field). This code could be used in a client script to get all of the button elements on a form, iterate through them, and remove any button on the form that doesn’t have ‘sysverb_update’ as the button ID value.

//Remove all buttons except for the 'Update' button
var items = $$('BUTTON').each(function(item){
   if(item.id != 'sysverb_update' && item.id != ''){
      item.hide(); 
   }
});

Disabling the form context menu

The need to disable the entire form section header context menu is extremely rare but may come in useful in certain situations. You can set up an onLoad client script like this to accomplish it.

function onLoad() {
   //Disable the context menu for non-admins
   if(!g_user.hasRole('admin')){
      //Disable all form section header context menus
      $$('tr.header').each(function(elmt) {
         Event.observe(elmt, 'contextmenu', clearMenus());
      });
      //Geneva and Beyond!
      var headerID = g_form.getTableName() + '.form_header';
      Event.observe($(headerID), 'contextmenu', clearMenus());
   }
}