Tag Archives | SharePoint

How to make a field in a SharePoint Edit form readonly

Paul Galvin showed how to hide a field in a SharePoint. I wanted to use this code to make a field “read only” once a from has been submitted. Forgetting about DataSheet view (for now), we can put a Content Editor Webpart on the top of the EditFrom.aspx page (to add a CEWP to the top of the edit from, append the URL to this -> EditForm.aspx?ToolPaneView=2) and include his code:


This will hide the filed based on the Column Name (Disclaimer). Taking this a step further, we can get the selected value (a drop down box in this case), and append a column after the hidden column with some formatting, a column name and the selected value. Effectively making the column readonly.

<script type="text/javascript">
$('tr:has(select[title=Disclaimer])').not('tr:has(tr)').append( '<tr><td nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">Disclaimer Accepted:</H3></TD><td valign="top" class="ms-formbody" width="400px">'+$('select[title=Disclaimer] :selected').text()+'</td></tr>');

How I created a “Copy to new item” functionality for a SharePoint list – Part 2

Second part. First Part can be found here. On the second page (NewForm.aspx), I grabbed out of the querystring the values for the source list item and the name of the list.
I used this person’s query string parser.

Then I used the following SOAP query :

$(document).ready(function() {
 var sourceID = getQuerystring('SourceID');
 var listName = getQuerystring('ListName');

 var soapEnv = &quot;&lt;soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'&gt; \
&lt;soapenv:Body&gt; \
&lt;GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'&gt; \
&lt;listName&gt;&quot; + listName + &quot;&lt;/listName&gt; \
&lt;viewName&gt;{GUID}&lt;/viewName&gt; \
&lt;viewFields /&gt; \
&lt;ViewFields /&gt; \
&lt;query&gt; \
&lt;Query&gt;&lt;Where&gt; \
&lt;Eq&gt; \
&lt;FieldRef Name='ID' /&gt; \
&lt;Value Type='Integer'&gt;&quot; + sourceID + &quot;&lt;/Value&gt; \
&lt;/Eq&gt; \
&lt;/query&gt; \
&lt;/GetListItems&gt; \
&lt;/soapenv:Body&gt; \

 async: false,
 url: &quot;http://site.com/subsite/_vti_bin/lists.asmx&quot;,
 type: &quot;POST&quot;,
 dataType: &quot;xml&quot;,
 data: soapEnv,
 complete: processResult,
 contentType: &quot;text/xml; charset=\&quot;utf-8\&quot;&quot;

 function processResult(xData, status) {
 $(xData.responseXML).find(&quot;z\\:row&quot;).each(function() {
 $(&quot;select[title='DropDown']&quot;).val($(this).attr(&quot;ows_DropDown&quot;)).attr(&quot;selected&quot;, &quot;selected&quot;); 

In the last three lines I changed the input box, textbox and dropdown boxes to their values in the results fromt the SOAP query.

Kinda fun. Just need to figure out how to do check boxes!

How I created a “Copy to new item” functionality for a SharePoint list – Part 1

I wanted to create a “copy to new item” functionality for a SharePoint list.

Steps I came up with:

  1. The first thing I had to do was add a link to the context menu (I learned that it is called an ECB) and have it point to the NewForm.aspx.
  2. Once I got that, I could append a querystring variable to the url that contained the “Source ID” of the item to copy and the name of the current list.
  3. Then I would grab that querystring value on the other side – in the NewForm.aspx page
  4. Next I would use that variable to query the SharePoint List via SOAP
  5. Inject the results the  into the form

Here is my script (add to a CEWP, I already have the jquery pointers to google in a Delegate control)

<script language="javascript">
function Custom_AddListMenuItems(m, ctx) {
var editURL = window.location.protocol + "//" + window.location.host + ctx.listUrlDir + "/NewForm.aspx?SourceID=" + currentItemID + "&amp;ListName=" + ctx.ListTitle;
 CAMOpt(m, "Copy To New Item" ,"window.location=('" + editURL + "');" , "/_layouts/images/Copy.GIF");

More to come.

How to add a webpart to a Sharepoint “NewForm.aspx”

I wanted to put a hidden CEWP on top of a standard SharePoint input form (you know when you click “NEW” too add an item to a list). The edit page was grayed out. I added to the querystring “NewForm.aspx?ToolPaneView=2” and I can add the CEWP to the top of the page. Once I added that, the edit page option is no longer grayed out.