locked
How to make "Audience Targeting" field mandatory in SharePoint 2010. RRS feed

  • Question

  • Hi,

    I have a very basic problem. I have a list on which I have enabled "Audience Targeting" and made this field required.

    But while adding item in the list, if I leave Audience Targeting filed empty than also I am able to add the item. Could someone explain why this vallidation is not working with Audience Targeting in sharepoint 2010?

    Thanks in advance!

    -Prashant

    Tuesday, May 13, 2014 9:54 AM

Answers

  • Use javascript to make it mandatory

    Here is similar thread to make field mandatory using jquery:

    http://stackoverflow.com/questions/6573487/jquery-validation-select-required-if-checkbox-checked

    Second way, you can edit your page (if you want this on list forms) in infopath designer and add data validation rule on field to make it mandatory based on chkbox selection.

    http://www.c-sharpcorner.com/UploadFile/anavijai/how-to-make-the-field-mandatory-in-sharepoint-2010-using-ecm/

    Java script to make it mandatory

    <scriptlanguage="ecmascript" type="text/ecmascript">

            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" />

    I found article which says its not possible to make is mandatory OOB

    http://stackoverflow.com/questions/731657/can-a-sharepoint-list-item-have-its-targeted-audience-calculated-or-otherwise-a

    • Marked as answer by Victoria Xia Wednesday, May 28, 2014 3:00 AM
    Tuesday, May 13, 2014 10:07 AM