Here's some simple JQuery to help you avoid looking for those annoying GUID's
var list = [];
var peoplePicker1;
var peoplePicker2;
var currentObject;
$(document).ready(function() {
// use this ^ for wildcard hiding/showing all items that begin with "xxx"
$('[title^="xxx"]').closest('tr').hide();
$('[title^="xxx"]').closest('tr').show();
$('DIV[id^="sectionSection2"]').hide();
// will need this to hide date/time fields
$('nobr:contains("Hire Car")').closest('tr').hide();
// use for text fields and drop down lists
var x = $('[title$="Authoriser"]').val();
// use for radio and checkboxes
// where title$ is the choice option
$('[title$="Enter Choice #1"]').click(function() {
alert('Please ensure you complete the Tracking section');
// get the radio button id
var tmp = $(this).children('input').attr('id');
// check its value
alert($("input[id="+tmp+"]:checked").val());
var checked = $("input[id="+tmp+"]:checked").val();
if(checked == 'on')
{
// do something
}
});
// use for people pickers
// add each people picker to an array and assign it to a var
// start loop
$(".ms-inputuserfield").each(function(){
list.push($(this).text());
currentObject = $(this);
});
// end loop
peoplePicker1 = list[0];
peoplePicker2 = list[1];
currentObject.attr('disabled','disabled');
var currentUser = $().SPServices.SPGetCurrentUser({
fieldName: "Title",
debug: false
});
// check if the user is an admin user
function isAdmin(user)
{
var adminUser1 = "System Account";
var adminUser2 = "john smith";
var adminUser3 = "john doe";
var adminUser4 = "dave nixon";
var adminUser5 = "fred smith";
if(user == adminUser1 || user == adminUser2 || user == adminUser3 || user == adminUser4 || user == adminUser5)
{
return "admin";
}
else
{
return "not admin";
}
}
function CheckForAttachment()
{
var elm = document.getElementById("idAttachmentsTable");
if(elm == null || elm.rows.length == 0)
{
alert("No e-training form attached");
return false;
}
else { return true; }
}
function PreSaveAction()
{
return CheckForAttachment();
}
});
Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts
26/04/2012
25/10/2011
jQuery readonly drop downs
Normally in SharePoint we would render a field or column as readonly by using the simple 'readonly' attribute.
********************** readonly field ***********************************
$("input[title='Some Field Name']").attr('readonly','readonly');
This is Ok for input fields but jQuery doesn't support the readonly attribute for drop down lists so you may be tempted to use the disable attribute
*********************** disable a field **********************************
$("select[title='Some Field Name']").attr('disabled','disabled');
However disabling a select control means that when you click Ok the actual value is not posted in the form and consequently the select value is not passed into the SharePoint column
********************** readonly field ***********************************
$("input[title='Some Field Name']").attr('readonly','readonly');
This is Ok for input fields but jQuery doesn't support the readonly attribute for drop down lists so you may be tempted to use the disable attribute
*********************** disable a field **********************************
$("select[title='Some Field Name']").attr('disabled','disabled');
However disabling a select control means that when you click Ok the actual value is not posted in the form and consequently the select value is not passed into the SharePoint column
Subscribe to:
Posts (Atom)