dinsdag 26 november 2013

Set a check or more checkboxes of a choice field selected.


A nice new function is created today for my colleague. 
If you want to check a checkbox of a checkbox field or a multi choice field, 
you can use the next function. 
You can call it by not knowing the GUID of the checkbox you want to select. But you can call it with 
the Display Name (Title) of your field. 
If it only one checkbox, you call it like this :
SetChoiceFieldValue ("YOUR TITLE", 1, true);
 
If you have a choice field with more options, you can select specific entries 
by setting the index to the checkbox you want to select. 
You can use the same function also to uncheck the field. You only have to set the last param to false. 

It's a nice jquery function that makes your scripting more flexible. 


 
function SetChoiceFieldValue(titel, index, b_checked)
{
        var TD = $('nobr:contains("'+ titel + '")').closest("td").next("td").find('input');
        if (index <= TD.length + 1)
        {
                TD[index-1].checked = b_checked;
        }
}

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