Saturday 12 April 2014

SharePoint number column should accept only numbers

Solution:

<script type="text/javascript">
        $(document).ready(function () {
            $('input[Title="ColumnName"]').keydown(function (e) {
                var keyCode = e.which; // Capture the event
                //190 is the key code of decimal if you dont want decimals remove this condition keyCode != 190
                if (keyCode != 8 && keyCode != 9 && keyCode != 13 && keyCode != 37 && keyCode != 38 && keyCode != 39 && keyCode != 40 && keyCode != 46 && keyCode != 110 && keyCode != 190) {
                    if (keyCode < 48) {
                        e.preventDefault();
                    }
                    else if (keyCode > 57 && keyCode < 96) {
                        e.preventDefault();
                    }
                    else if (keyCode > 105) {
                        e.preventDefault();
                    }
                }
            });
        });
       
</script>


How to set subsite page as main site home page

In SharePoint it’s easy to set main site homepage from main site itself.
But today I want to set my main site homepage using my sub-site webpage.

Solution:

    1) After little bit googling I am getting one of the way, we need to change the web.config file of SharePoint.
    2) To open web.config go to C:\Inetpub\wwwroot\port_number.
   3) Open web.config file and add following lines of code under system.web tag.

<urlMappings enabled="true">

<add url="~/" mappedUrl="/subsite/SitePages/Page.aspx"/>

</urlMappings>


Feel free to revert in-case of any query...


Product Applies To:

·         SharePoint Server 2010

·         SharePoint Foundation 2010

How to add checkbox for every item in Data Form Webpart

How to add checkbox for every item in Data Form Web Part

In my one of view I want to use Data Form Web Part as well as I want to know every item’s ID value. In SharePoint XSLT view checkbox against every item is by default available but in DFWP is not readily available.


After little bit googling i am getting following step to check box column in DFWP
1.       In web part page add your DFWP.
2.       Add or remove your columns as per requirement.
3.       Click on design tag from ribbon, add one more column to your view.
4.       Select your newly added column, click on insert tab from ribbon add checkbox control from HTML toolbox.
5.       Set the “value” property of checkbox to use ID column’s value.



Feel free to revert in-case of any query...


Product Applies To:

·         SharePoint Server 2010

·         SharePoint Foundation 2010

Wednesday 15 January 2014

SharePoint 2013 e-books list

·         Professional SharePoint 2013 Development

·         Professional SharePoint 2013 Administration

·         Microsoft SharePoint 2013 App Development

·         Beginning SharePoint 2013

·         Microsoft SharePoint 2013 Developer Reference

·         Beginning SharePoint 2013 Development

·         Explore SharePoint 2013

·         Deployment guide for SharePoint 2013

·         Test Lab Guide: eBook for SharePoint Server 2013 Intranet and Team Sites

·         SharePoint Server for Business Intelligence
http://ligman.me/11HTPhn


·         Pro SharePoint 2013 Branding and Responsive Web Development

Friday 10 January 2014

Set SharePoint form field show, hide or read-only using JavaScript

Sometimes from validation point of view we need to hide, visible or read only SharePoint List from fields.This blog will give us idea about how to do that using JavaScript.

·         Set SharePoint form field read-only:

<script type ="text/javascript">
function SetReadOnly()
{
var elements=document.getElementById('ctl00_m_g_adee8cfa_dbff_48bf_b75c_ae50351ebbf7_ff21_ctl00_ctl00_TextField');
elements.readOnly=true;
}
_spBodyOnLoadFunctionNames.push("SetReadOnly()");
</script>


·         Hide SharePoint form field:

$("# ColumnID").hide();


·         Show SharePoint form field:

$("#ColumnID").show();

Remark: Here "ColumnID" is id for that particular column specify in <tr> tag on SharePoint form  
Eg. <tr id=”ColumnID”>

Example:
·         show and hide SharePoint form field base on dropdown value change in sharepoint

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("ourFunctionName");

function ourFunctionName()
{
$("Select[Title='Type']").change(function () {
var val=$("Select[Title='Type']").val();

if(val=="Pre")
{
$("#Post").hide();
$("#Pre").show();
}
else if(val=="Post")
{
$("#Post").show();
$("#Pre").hide();
}
});
}
</script>

Handling event of SharePoint form dropdown value change

Problem Description:

Many times we want to perform event handling on SharePoint list’s form.
This blog will give us idea about “Choice” column value change event handling.

As usual add Content Editor WebPart into SP list form and copy paste below code into HTML form.


<script type="text/javascript">

_spBodyOnLoadFunctionNames.push("ourFunctionName");

function ourFunctionName()
{

$("Select[Title='ColumnName']").change(function () {
alert("Choice column value changed");
});
}

</script>

Reference:



Remark:

For Date and Time column is quite different, for that follow below link,


Nice article written by Ruud Stijger.


Check Box control on SharePoint form

How to check value of checkbox control on SP form:

var EligibleValue=$("#ctl00_m_g_baacd937_c4ae_4d2d_9436_57c6bbb65904_ff191_ctl00_ctl00_BooleanField").is(":checked");

alert(EligibleValue);






How to set uncheck value of checkbox control on SP form:
   
$("#ctl00_m_g_baacd937_c4ae_4d2d_9436_57c6bbb65904_ff191_ctl00_ctl00_BooleanField").attr('checked', false);





How to set check value of checkbox control on SP form:
   
$("#ctl00_m_g_baacd937_c4ae_4d2d_9436_57c6bbb65904_ff191_ctl00_ctl00_BooleanField").attr('checked', true);





Get current list name of new-edit form using javascript

Problem Description:

While playing with JavaScript, today I require List name of current form (new, edit).
After little bit googlling i am getting some scripts but there are some bugs.
after working with that all scripts, final scripts is ready to use, as below....

var clientContext = SP.ClientContext.get_current();
oWeb = clientContext.get_web();
oListColl = oWeb.get_lists();
var currentListGUID = SP.ListOperation.Selection.getSelectedList();
var ListName="";
if (currentListGUID === null)
{
        ListName = $(".s4-titletext h2 a:first").html(); //requires JQuery to get list name from ribbon
}
else
{               
        ListName=currentListGUID;
}

That's all...!!!




Wednesday 8 January 2014


Problem Description:

How to set default values to SharePoint form control using javascript.

Resolution:


Add below script in SharePoint form content editor web part :

<script type="text/javascript">

$(document ).ready(function() {
$("#Control_Name_From_Page_View_Source").val("Default_Value");
});


</script>


Problem Description:

Set default value to column via Powershell.

Resolution:


$w = Get-SPWeb http://localhost
$l = $w.GetListFromUrl("/Lists/RequestList/DefaultStatus.aspx")
$f = $l.Fields["Status"]
$f.DefaultValue = "Delivered"
$f.Update()


Feel free to revert in-case of any query...


Product Applies To:

·         SharePoint Server 2010
·         SharePoint Foundation 2010
·         SharePoint Server 2013



Limitation of javascript in sharepoint column name length

Problem Description:

My one of the SharePoint list column length is more than 30 characters (commented part in below image), but at the time of item updation it gives me error.
So i check with Debugger then i found column length mistake.
Because of JavaScript column length limitation if actual column name having more than 30 characters,it will take character maximum as 30 (see red circle in image).




Add items and removing all option of dropdown box in javascript

Add items and removing all option of dropdown box in javascript


How to add items in dropdown using JavaScript
<script type="text/javascript">
    function AddItem(Text,Value)
    {
        // Create an Option object       
        var opt = document.createElement("option");
      // Add an Option object to Drop Down/List Box
        document.getElementById("DropDownList").options.add(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;
    }
<script />


Removing all option of dropdown box in JavaScript

document.getElementById('id').options.length = 0;

Add item into SharePoint list using javascript

In this blog, we learn how to add item into SharePoint list using JavaScript.

Below function add to the content editor webpart or into your core .js file,and call on link click or button click.

<script type="text/javascript">
// Make sure the SharePoint script file 'sp.js' is loaded before your
// code runs.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
function createListItem()
{
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('InwardOutward');
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
   oListItem.set_item('Title', 'My New Item!');
   oListItem.update();
    clientContext.load(oListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded()
{
    alert('Item created: ' + oListItem.get_id());
 }
function onQueryFailed(sender, args)
{
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>

<a href="javascript:createListItem();"><img alt="Add" src="/Image_/add.png" border="0"/></a>

While using JavaScript to add item into list following error may occurred: