zondag 4 augustus 2013

Disable Save button on an Edit Form and the Ribbon Save Button


If you want to play with the Save button of Sharepoint, and also the save buttons in the ribbon,
you can use the next script in a Content Editor webpart. 
I have written my own custom Function for this nice functionality that I use all the time since I wrote it.
It let me help to prevent the Save action for users when your Item has a certain status. 
But not with playing with the security! 

I use a Status field that has the type Choise Field. 
Here I put the different steps that my form can have. For example a step for Acceptation,
or a step for Refusing, Canceling, etc. 
When for example a form has the step Refused, nobody my edit the item anymore. 
You can do this by playing with 
security settings in a workflow, but you risk that the workflow isn't executed directly. 
At that moment somebody can still change the item!
And Item Level Security on big lists aren't supported! 

With this method, you prevent that nobody save changes in your custom Edit form 
when the Item field Status has a certain value. 
And you can specify some administators, or a second EditForm where you can allow to edit 
the Item for an intervention. 

If you have remarks, please let me know... 
  

$(document).ready( function() {
            checkStatusForSave();
});

  

function checkStatusForSave()

{
// I use a custom Status Choise field for workflow actions. 
   var fieldStatusRef = $(':select[title="Status"]');
   var StatusRef = $(':select[title="Status"]').val();
   switch (StatusRef)
        {
            case 'Waiting for action A':
// the Item may be saved.
                        disableSave(false);
            break;
            case 'Refused':
// you may not save any changes to the Item.
                        disableSave(true);

            break;
            default:
        }
}

function disableSave(bAlways)
{

 if($(':span[title="Open Menu"]').text().indexOf('FILL IN YOUR NAME SO YOU CAN SAVE ITEMS') == -1)
 { // not an administrator
      if (bAlways)
      {
          $(':input[value="Save"]').attr("disabled",true);
          $("span.ms-cui-ctl-largelabel:contains('Save')").parent("a").hide();
      }
      else
      {
          if ($(':span[title="Open Menu"]').text().indexOf($(':input[title="Title"]').val()) != -1)
          {
              $(':input[value="Save"]').attr("disabled",true);
              $("span.ms-cui-ctl-largelabel:contains('Save')").parent("a").hide();
          }
          else
          {
              $(':input[value="Save"]').attr("disabled",false);
              $("span.ms-cui-ctl-largelabel:contains('Save')").parent("a").show();
          }
      }
 }
}
 

Geen opmerkingen:

Een reactie posten