IntroductionIn this article you will see how to make a field mandatory in SharePoint 2010 using ECMAScript. I have a list named "List Request" which has the following fields (Navigate to the list, click on List tab in the ribbon interface. Click on List Settings button).I am going to make the field named "Date" as mandatory field using ECMAScript.Steps Involved
var fieldCollection; var field; var list;
function fieldRequired() { var clientContext = SP.ClientContext.get_current(); if (clientContext != undefined && clientContext != null) { var webSite = clientContext.get_web(); this.list = webSite.get_lists().getByTitle("List Request"); this.fieldCollection = list.get_fields(); this.field = fieldCollection.getByTitle("Date"); this.field.set_required(true); this.field.update(); clientContext.load(this.field); clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed)); } }
function OnLoadSuccess(sender, args) { alert(this.field.get_required()); }
function OnLoadFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); }</script> <input id="btnFieldRequired" onclick="fieldRequired()" type="button" value="Set Required Field" />
Reference
SummaryThus in this article you have seen how to make the field mandatory in SharePoint 2010 using ECMAScript.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: