SPArrangeChoices for all columns?

Jun 17, 2011 at 5:50 PM

I have a list with almost 200 columns.  Each on is a choice using radios.  Is there a parm to ArrangeChoices so that the behavour is for all the coumns on a page?

Coordinator
Jun 17, 2011 at 5:52 PM

Steve:

No, and that's intentional. However, you can certainly wrap a call to the function in a selector which selects all of the radio buttons on your page.

M.

p.s. That's a hefty list!

Dec 2, 2011 at 1:57 PM

steve/marc

I have the same need - a list with approx 150 questions with the same three radio button responses.  The clients are apt to change the display name, and break my code

Being a javascript newbie (ok, a non formally trained js'er), Marc's suggestion is over my head!

Can someone post a simple example I can mimic?

Thanks!!!

Bill

Dec 2, 2011 at 3:33 PM
It's been a while, but not get you discouraged, JQuery takes some time to learn. Marc is the real expert here. However...you needn't worry about the clients changing the name. Use the JQuery selector and go directly at the elements class. Sorry but I'm way too busy on a current project hat is coming due to post anything. I suggest http://www.w3schools.com/jquery/jquery_ref_selectors.asp and http://jsfiddle.net/


From: will266 [email removed]
Sent: Friday, December 02, 2011 9:58 AM
To: Aras, Stephen
Subject: Re: SPArrangeChoices for all columns? [SPServices:261802]

From: will266

steve/marc

I have the same need - a list with approx 150 questions with the same three radio button responses. The clients are apt to change the display name, and break my code

Being a javascript newbie (ok, a non formally trained js'er), Marc's suggestion is over my head!

Can someone post a simple example I can mimic?

Thanks!!!

Bill




This e-mail transmission may contain information that is proprietary, privileged and/or confidential and is intended exclusively for the person(s) to whom it is addressed. Any use, copying, retention or disclosure by any person other than the intended recipient or the intended recipient's designees is strictly prohibited. If you are not the intended recipient or their designee, please notify the sender immediately by return e-mail and delete all copies.
Dec 2, 2011 at 9:32 PM

Thanks for the feedback - I have been plowing through, but am really having a hard time making the leap!

I am stuck trying to find a way to grab the NOBR of FieldInternalName when the FieldType=SPFieldChoice or the span class is ms-RadioText...

The best I can do is have it apply the logic to all columns, which is slow, wrong and gives odd results on certain field types.

Here is my code - any direction would be appreciated!!

<SCRIPT type=text/javascript>
var colName;

$(".ms-formlabel").each(function() {
   colName = $(this).find("nobr").html();
   $().SPServices.SPArrangeChoices({
	columnName: colName,
	perRow: 3
      });
  });

</script>

Coordinator
Dec 4, 2011 at 5:53 PM

Will and Steve:

There's a function called findFormField that I use in SPServices to find specific radio button or checkbox columns that may help here.

The FieldType for radio buttons is FieldType="SPFieldChoice" and for checkboxes, it's FieldType="SPFieldMultiChoice". so you could adapt the findFormField function below to find all of those elements and run SPArrangeChoices on them.

M.

 // Finds the td which contains a form field in default forms using the comment which contains:
 //   <!--  FieldName="Title"
 //   FieldInternalName="Title"
 //   FieldType="SPFieldText"
 //    -->
 // as the "anchor" to find it. Necessary because SharePoint doesn't give all field types ids or specific classes.
 function findFormField(columnName) {
  var thisFormBody;
  // There's no easy way to find one of these columns; we'll look for the comment with the columnName
  var searchText = RegExp("FieldName=\"" + columnName.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "\"", "gi");
  // Loop through all of the ms-formbody table cells
  $("td.ms-formbody, td.ms-formbodysurvey").each(function() {
   // Check for the right comment
   if(searchText.test($(this).html())) {
    thisFormBody = $(this);
    // Found it, so we're done
    return false;
   }
  });
  return thisFormBody;
 } // End of function findFormField

 

Dec 7, 2011 at 2:12 PM

Ended up seeing a posted sample on "GetList"

this ended up working for me:

$().SPServices({
  operation: "GetList",
  listName: "{list guid here}",
  completefunc: function(xData, Status) {
      $(xData.responseXML).find("Fields>Field").each(function() {
	var $node = $(this);
        var type = $node.attr("Type"); 
        var dispName = $node.attr("DisplayName");
   if(type=="Choice"){
     $().SPServices.SPArrangeChoices({
	columnName: dispName,
	perRow: 3
        });
     }
     });
   }
});

Dec 7, 2011 at 2:15 PM

cool. glad you found it. so this code arranges every choice field in certain list horizontally?


From: will266 [email removed]
Sent: Wednesday, December 07, 2011 10:13 AM
To: Aras, Stephen
Subject: Re: SPArrangeChoices for all columns? [SPServices:261802]

From: will266

Ended up seeing a posted sample on "GetList"

this ended up working for me:

$().SPServices({
  operation: "GetList",
  listName: "{list guid here}",
  completefunc: function(xData, Status) {
      $(xData.responseXML).find("Fields>Field").each(function() {
	var $node = $(this);
        var type = $node.attr("Type"); 
        var dispName = $node.attr("DisplayName");
   if(type=="Choice"){
     $().SPServices.SPArrangeChoices({
	columnName: dispName,
	perRow: 3
        });
     }
     });
   }
});




This e-mail transmission may contain information that is proprietary, privileged and/or confidential and is intended exclusively for the person(s) to whom it is addressed. Any use, copying, retention or disclosure by any person other than the intended recipient or the intended recipient's designees is strictly prohibited. If you are not the intended recipient or their designee, please notify the sender immediately by return e-mail and delete all copies.
Feb 29, 2012 at 1:50 PM

Thank you will266 ... at last something that works in a survey custom form.  Much gratitude!  :-)

Apr 2, 2013 at 7:43 PM
Edited Apr 2, 2013 at 8:04 PM
Hey Will266 and jriesen...I've been unsuccessful in getting this piece of code to work. Please review and let me know if I'm missing something. I'm a noob with Javascript, but understand what the code should do, but when I load the userform, nothing has changed. I've been successful in getting the individual items to load, but to the point of this post, I too have a list with more columns than I'd like to add manually.

I work in a fast changing environment, so working with each column individually has been very time consuming and not adventageous for our business model.

Let me know your thoughts?

Do I still put <xsl:comment>FieldName="WhateverTheNameIs"</xsl:comment> for each item?
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script language="javascript" type="text/javascript" src=".../SiteAssets/Scripts/jquery-1.8.3.js"></script>
<script language="javascript" type="text/javascript" src=".../SiteAssets/Scripts/jquery.SPServices-0.7.2.js"></script>
<script language="javascript" type="text/javascript">
$().SPServices({
  operation: "GetList",
  listName: "{I Entered My List ID}",
  completefunc: function(xData, Status) {
      $(xData.responseXML).find("Fields>Field").each(function() {
    var $node = $(this);
        var type = $node.attr("Type"); 
        var dispName = $node.attr("DisplayName");
   if(type=="Choice"){
     $().SPServices.SPArrangeChoices({
    columnName: dispName,
    perRow: 3
        });
     }
     });
   }
});
</script>
Coordinator
Apr 5, 2013 at 3:11 AM
Kep:

It looks like this should work. You could also just look for all of the radio buttonm or checkbox columns in the page and call SPArrangeChoices on that set of columns.

Are you sure that the references to the script files are correct?

M.
Jul 24, 2013 at 8:22 PM
Sorry for the late response. I got it to work...However, my userform is timing out on the initial load, but when I click refresh on the SharePoint page the form loads without the choices aligned horizontal, then quickly changes to horizontal after the form loads.

My question is, what can I do to fix the form timeout issue on the inital request?

Thanks!
Coordinator
Jul 26, 2013 at 1:14 AM
Keep in mind that this is script that runs once the page is loaded. The radio buttons will load as usual and then the function does its thing. if it's onerous, hide the column until after it rearranges.

m.