Friday, May 24, 2013

Customize the List View in SharePoint Designer 2013

 How to style the List View webpart in SharePoint Designer 2013?

With the missing design view in SharePoint Designer 2013 the designing part of simple webparts is now a bit complicated.

Here I discuss the designing of a List View webpart.
  
The first step is to bring up the List View Tools . To do this just click anywhere in the List view webpart code.
Go to the Design tab and click on the Customize XSLT. Select the Customize Entire View and click.
This expands the list view XSLT code and provides us the opportunity to make changes. 
 
Customize XSLT
 
In the XSLT we need to find the places where the attribute class is defined for the components/templates we want to design. It will be something like the code shown below.
Here we can provide our own class name and define the styles for that using the CSS.
 
 
I hope this helps you a bit. If you have a better solution. Please post in comments.


Friday, May 17, 2013

Using People Picker field in SharePoint Workflow initiation Form


In the SharePoint initiation form, if we need a field which takes alias and checks it against valid users and gives the name(just like the out of box people picker field) ,we can use the process given here.
 
 
In the initiation form if an initiation form parameter is selected as People/Group type, in the form it shows as dropdown list. The dropdown is populated with all the user values. If the number of users is large(which generally is),the initiation form will take too much time to load. Also the selection of any value from a very long dropdown is cumbersome.
If the field is a people picker ,then an alias can be entered and checked.
 
The plan is to take a people picker field and a hidden text field. The people picker field will give us all the functionality of selecting and checking names. The value from this field will be passed to the hidden text field which is binded to the initiation parameter.
Steps:
1.       Add an initiation form parameter of type text in the workflow.
2.       Save and publish the workflow.
3.       Open the aspx form associated with the workflow
4.       Here the initiation form field of type text can be seen. Add the following control in a new row
<SharePoint:PeopleEditor id="pplPicker" runat="server" allowempty="true" validatorenabled="True" onvaluechangedclientscript="SetPeopleValues()" MultiSelect="False" allowtypein="True">
</SharePoint:PeopleEditor>
<!-- onvaluechangedclientscript property calls the JavaScript function-->
5.       To add the JavaScript function add this header just before the <asp:content> tag with contentplaceholderid=PlaceHolderMain
<asp:Content    id="Content1"     runat="server"     contentplaceholderid="PlaceHolderAdditionalPageHead">
<script type="text/javascript">
    function SetPeopleValues()
{             
    //Retrieve the semi-colon separated list of user id's (in this case only one as Multiselect =”false”)  
     var people = document.getElementById('ctl00_PlaceHolderMain_InitiationForm_pplPickerID0EAAA_upLevelDiv').innerText; 
//Populate the text form field
    document.getElementById('ctl00_PlaceHolderMain_InitiationForm_ff11_1').value = people;  //'ctl00_PlaceHolderMain_InitiationForm_ff11_1' is the id of the text form field
}
  </script> </asp:Content>
6.       Now on the onclick event of the OK button add the function.
<input type="button" value="OK" name="btnSave" class="ms-ButtonHeightWidth" onclick="javascript:SetPeopleValues()
7.       Lastly put style="display:none" for the text form field.
 
 

Monday, April 8, 2013

SharePointDVDropDown Field not saving correct value and EnableViewState=”false”


The buildup: 
I had a SharePoint list form with more than 20 fields. For a form field of type look-up, I had removed the SharePoint out-of-box field and put a  SharePointDVDropdown. To this I attached a data-source from another list (this is great trick to filter the default drop-down which appears for look-up columns).
I had few date fields as well. 

The strange behavior: 
I select a value from the SharePointDVDropdown say option1. Give an invalid entry in date field. Submit the form.SharePoint validates the date field and returns error as Invalid format. Now I change the value in SharePointDVDropdown to say option2. Give a valid date and submit.

I go to the list and check the item created, the value saved in field corresponding to the SharePointDVDropdown is option1 !!!!! instead of option2. 

The culprit:    
After lot of painstaking hours and hair pulling the culprit was found. There is a property called  EnableViewState in SharePointDVDropDown. If set to "true" this little thing saves the value of the field between server requests. Now since the calendar field gets validated at server side, the value option1 remains saved even if the value is changed from the drop down.

The solution:
While using SharePointDVDropDown field remember to put EnableViewState=”false”. This is because , if there is any server side validation then the value entered before the validation is done, persists in the dropdown and even if the value is changed , it still takes the previous value as input.