maandag 14 oktober 2013

Filter inputfields on a Sharepoint Field for instantly filtering


Had a customer today that wanted a online filtering on a table. 
Found out next part of code in a previous project in Sharepoint 2007 of an old colleague. 
And like it or not, but it also works in Sharepoint 2010.
It is a simple script that adds input fields below each column of your Sharepoint View. 
When entering a text in a column filter field, it hides all rows of your View that not 
corresponds with the value that you have added. 

Have fun with it ! 

$(document).ready(function()
{
 jQuery.extend(jQuery.expr[':'], {
 containsIgnoreCase: function(a,i,m) {return (a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0}
});

$("table tr.ms-viewheadertr").each(function()
{
    if($("td.ms-vh-group", this).size() > 0)
    {
        return;
    }
    var tdset = "";
    var colIndex = 0;
    $(this).children("th,td").each(function()
    {
        if($(this).hasClass("ms-vh-icon"))
        {
            // attachment
            tdset += "";
        }
        else
        {
            // filterable
            tdset += ">input class="vossers-filterfield" filtercolindex="" + colIndex + "" type="text" />>br />
";                                                          
        }
        colIndex++;
    });
    var tr = "" + tdset + "";
    $(tr).insertAfter(this);
});          

$("input.vossers-filterfield")
    .css("border", "1px solid #7f9db9")
    .css("width", "100%")
    .css("margin", "2px")
    .css("padding", "2px")
    .keyup(function()
 {                                            
  var inputClosure = this;
  if(window.VossersFilterTimeoutHandle)
  {
   clearTimeout(window.VossersFilterTimeoutHandle);
  }
  window.VossersFilterTimeoutHandle = setTimeout(function()
  {
   var filterValues = new Array();
   $("input.vossers-filterfield", $(inputClosure).parents("tr:first")).each(function()
   {                                                            
    if($(this).val() != "")                                                     
    {
     filterValues[$(this).attr("filtercolindex")] = $(this).val();
    }
   });                          
   $(inputClosure).parents("tr.vossers-filterrow").nextAll("tr").each(function()
   {
    var mismatch = false;
    $(this).children("td").each(function(colIndex)
    {
     if(mismatch) return;
     if(filterValues[colIndex])
     {
      var val = filterValues[colIndex];
      // replace double quote character with 2 instances of itself
      val = val.replace(/"/g, String.fromCharCode(34) + String.fromCharCode(34));                                                                                                      
      if($(this).is(":not(:containsIgnoreCase('" + val + "'))"))
      {
       mismatch = true;
      }                                                                                           
     }
    });
    if(mismatch)
    {
     $(this).hide();
    }
    else
    {
     $(this).show();
    }                             
   });                                                         
  }, 250);
    });
});

 

zaterdag 12 oktober 2013

Check if a Multi Selectable Sharepoint Choice Field value is Checked.


I'm starting to write my own sharepoint helperclass with functions 
that can be called without knowing the ID's of the Sharepoint Fields, 
but by using the field Display Names. 

This function is to know if a certain value of a multi selectable 
choice field is checked or not.


// call the function
// CheckChoiceFieldValue ("DISPLAYNAME", 1) check of first value is checked
// CheckChoiceFieldValue ("DISPLAYNAME", 2) check of second value is checked
  
function CheckChoiceFieldValue(titel, index)
{
 var TD = $('nobr:contains("'+ titel + '")').closest("td").next("td").find('input');
    var bTD = false;
    if (index <= TD.length + 1)
    {
  return TD[index-1].checked;
 }
    return false;
}
 

vrijdag 11 oktober 2013

Disable a Hyperlink field without knowing the ID of your Sharepoint Field


I'm starting to write my own sharepoint helperclass with functions 
that can be called without knowing the ID's of the Sharepoint Fields, 
but by using the field Display Names. 

This function is to Disable or Enable a Sharepoint Hyperlink Field.


// call the function
// DisableHttpLink ("DISPLAYNAME", True) to disable the field
// DisableHttpLink ("DISPLAYNAME", False) to enable the field
  
function DisableHttpLink(titel, b_disable)
{
 var TD = $('nobr:contains("'+ titel + '")').closest("td").next("td").find('input');
    for(var i = 0; i < TD.length;i++)
    {
  $("#" + TD[i].id).attr("disabled",b_disable);
    }
}
 

donderdag 10 oktober 2013

Disable a Choice field without knowing the ID of your Sharepoint Field


I'm starting to write my own sharepoint helperclass with functions 
that can be called without knowing the ID's of the Sharepoint Fields, 
but by using the field Display Names. 

This function is to Disable or Enable a Sharepoint Choice Field.


// call the function
// DisableAChoiceField ("DISPLAYNAME", "input|select", True) to disable the field
// DisableAChoiceField ("DISPLAYNAME", "input|select", False) to enable the field
  
function DisableAChoiceField(titel, type, b_disable)
{
    if (type == "input")
  var TD = $('nobr:contains("'+ titel + '")').closest("td").next("td").find('input');
    if (type == "select")
  var TD = $('nobr:contains("'+ titel + '")').closest("td").next("td").find('select');
    for(var i = 0; i < TD.length;i++)
    {
  $("#" + TD[i].id).attr("disabled",b_disable);
    }
}
 

woensdag 9 oktober 2013

Disable a PeoplePicker Field without knowing the ID of your Sharepoint Field


I'm starting to write my own sharepoint helperclass with functions 
that can be called without knowing the ID's of the Sharepoint Fields, 
but by using the field Display Names. 

This function is to Disable or Enable a Sharepoint PeoplePicker Field.


// call the function
// DisablePeoplePicker ("DISPLAYNAME", True) to disable the field
// DisablePeoplePicker ("DISPLAYNAME", False) to enable the field
  
function DisablePeoplePicker( titel, b_disable)
{
    $('nobr:contains("'+titel+'")').closest("td").next("td").find("div").attr("contentEditable",false);
    if (b_disable)
    {
        $('nobr:contains("'+titel+'")').closest("td").next("td").find("div").css("backgroundColor","silver");
        $('nobr:contains("'+titel+'")').closest("td").next("td").find("img").hide();
    }
    else
    {
        $('nobr:contains("'+titel+'")').closest("td").next("td").find("div").css("backgroundColor","white");
        $('nobr:contains("'+titel+'")').closest("td").next("td").find("img").show();
    }
}
 

dinsdag 8 oktober 2013

Disable a Date field without knowing the ID of your Sharepoint Field


I'm starting to write my own sharepoint helperclass with functions 
that can be called without knowing the ID's of the Sharepoint Fields, 
but by using the field Display Names. 

My first function isn't complete yet.
Disable or Enable a Date Field.
It will be completed very soon with the type "DateTime". 


// call the function
// DisableDateField ("DISPLAYNAME", "Date", True) to disable the field
// DisableDateField ("DISPLAYNAME", "Date", False) to enable the field
  
function DisableDateField (titel, type, b_disable)
{
    if (type == "Date")
 {
        $(':input[title="'+titel+'"]').attr("disabled",b_disable);
        if (b_disable)
            $(':input[title="'+titel+'"]').closest("td").next("td").hide();       
        else
   $(':input[title="'+titel+'"]').closest("td").next("td").show();
 }
}
 

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();
          }
      }
 }
}