Monday, November 24, 2014

Arrange Choice Field Radio Buttons Horizontally in SharePoint List Forms

Requirement is to arrange choice fields of Radio buttons to horizontally in a SharePoint 2013 custom list form:
How to arrange choice field options Horizontally?
Step 1: Create new Custom list form(Say: New.aspx) using SharePoint Designer, Edit the page in SharePoint designer, Find and wrap your choice field in <Span> tag to assign it a unique ID. E.g.optRegType.

<span id="optReqType">
 <SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="New" FieldName="Change_x0020_Request_x0020_Type" __designer:bind="{ddwrt:DataBind('i',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Change_x0020_Request_x0020_Type')}"/>
       <SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="Change_x0020_Request_x0020_Type" ControlMode="New"/>
</span>

Step 2: In the custom list form, find the tag <AdditionalPageHead> and add this code just below it.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

  $(document).ready(function() {
 var firstRadio = $("#optReqType table tbody tr td .ms-RadioText:eq(0)");
 $("#optReqType table tbody tr td .ms-RadioText:gt(0)").appendTo($(firstRadio));

  });
</script>
 
What If you have Multiple Choice Fields?
When you have multiple choice fields in the form, its better to create a function to arrange them horizontally.
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

 function alignOptions(fieldName)
 {
 var firstRadio = $("#"+fieldName +" table tbody tr td .ms-RadioText:eq(0)");
 $("#"+fieldName +" table tbody tr td .ms-RadioText:gt(0)").appendTo($(firstRadio));
 }
 
  $(document).ready(function() {

   //Call function to arrange Radio buttons horizontally
 alignOptions("optChgImpact");
 alignOptions("optChgPriority");

  });
</script>
Here is my screen:
SPServices Framework also offers this functionality:
http://spservices.codeplex.com/wikipage?title=%24%28%29.SPServices.SPArrangeChoices



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

14 comments :

  1. waw!! it workss

    ReplyDelete
  2. I can't seem to find in the new form I'm working on. The only thing I can find is this:

    Although it's highlighted in yellow. Any thoughts?

    ReplyDelete
    Replies
    1. Instead of Default NewForm.aspx, Try creating your own Custom Form!

      Delete
    2. Yes a New Custom Form was created. Is there another custom form that I'm not aware of? I should elaborate a little better because my previous post I forgot to mention that I'm not able to find the AdditonalPageHead tag as you described it previously in your article.

      Delete
  3. How did you get Bar above Objective "Details of Change". please help me i am trying to design a form with section title.

    ReplyDelete
    Replies
    1. In your Custom NewForm.aspx, Search for : <asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

      and insert the below code to it:

      <style type="text/css">
      .GroupHeader
      {
      background-color:gray;
      width:500px;
      color:white;
      font-weight:bold;
      height:25px;
      text-align:center;
      border:1px;
      }
      </style>

      Now, You can use this style anywhere. E.g.
      <tr class="GroupHeader"><td colspan="2">Details of Change</td> </tr>

      Delete
  4. Cool! Is there a way to align the choices if the choice names are not of the same width. In my case, I have around 40 choices and the choice names are not the same size. When the choices wrap into the second, third lines... the choices don't look nice.

    [ ] choice 1 [ ] choice two [ ] another long choice that wraps down [ ] choice four [ ] choice 5 [ ] choice six [ ] choice 7 [ ] choice eight

    ReplyDelete
  5. I 100% cannot get this to work. Any helpers?

    ReplyDelete
  6. Is there any way I can add more spacing between the radio buttons?

    ReplyDelete
    Replies
    1. Sure, Add this CSS to the page:

      #ProjectType Label, .ms-RadioText{
      padding-left: 2px;
      }
      #ProjectType .ms-RadioText{
      padding-left: 10px;
      }

      Don't forget to change the radio group's Span ID (ProjectType)!

      Delete
  7. How it works if i have more one question of multiple choice radiobutton???
    should I change the span id become optreq1, optreq2? and var become firstradio, secondradio?
    its not simple :(

    ReplyDelete
    Replies
    1. Simple! Wrap your choice fields inside different SPAN IDs and Use the code under "What If you have Multiple Choice Fields?" section!

      Delete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...