Showing posts with label content editor. Show all posts
Showing posts with label content editor. Show all posts

Friday, February 12, 2016

How to Hide a web part for selected users in Sharepoint

JQuery:

We ll do get div id or class for particular webpart

display:none




SharePoint Feature:

Edit page


  • Edit webpart properties in current page
  • web part's properties panel expand the Advanced section, scroll to the bottom and select the Target audience to hide the web part.
  • Save your changes and test by have a group member, and a non-group member, log in and see if the web part is displayed.

How to get list in Content Editor Web Part using JavaScript Client Side Object Model


<button onclick='GetFieldDetails()'>Get Details</button>

<script type="text/javascript">

function GetFieldDetails()
{
  var listname = "Employee";
  var context = SP.ClientContext.get_current();
  this.web = context.get_web();
  context.load(this.web);
  this.list = web.get_lists().getByTitle(listname);
  context.load(this.list);
  this.fields = this.list.get_fields();
  context.load(this.fields); 

  context.executeQueryAsync(Function.createDelegate(this, this.getListInfoSuccess), Function.createDelegate(this, this.getListInfoFail));
}

function getListInfoSuccess(sender, args) 
{
        var fieldEnumerator = this.fields.getEnumerator(); 
        var results="";
        while (fieldEnumerator.moveNext()) { 
            var oField = fieldEnumerator.get_current(); 
            if (!oField.get_hidden())
            results+= oField.get_title()
                + " - " + oField.get_internalName()
                + " - " + oField.get_hidden()
                + "\n";
        }
        alert(results);
}    
function getListInfoFail(sender, args) 
{
 alert('Something failed. Error:'+args.get_message());    
}

</script>

What is the PreSaveAction

We have added a PreSaveAction JavaScript function to the page.

Return a True or False to allow the save to continue.
Example:

<script type="text/javascript">
 function PreSaveAction() {
  // pre save action alert message
  alert('form has been submitted!');
  return true;  // return true to continue with the save 
       // return false;          // or return false to cancel the save
 } 
</script>