This is a draft/example to keep Steve busy over the weekend 🙂 (see his request here).
To get anything out of this code, you have to read the following articles: Tabs in SharePoint form and Accordion in SharePoint form
Here is the code:
<!-- Date field text size --> <style type="text/css"> .ms-dtinput,.ms-dttimeinput{ font-size:0.7em; } </style> <DIV id="tabs"> <UL style="font-size:12px"> <LI><A href="#tabs-1">Tab 1</A></LI> <LI><A href="#tabs-2">Tab 2</A></LI> <LI><A href="#tabs-3">Tab 3</A></LI> </UL> <div id="tabs-1"> <div id="accordion-1"> <H3><A href="#accordion-0">Tab 1 Accordion 1</A></H3> <div><table width="100%" id="accTable-0"></table>&nbsp;</div> <H3><A href="#accordion-1">Tab 1 Accordion 2</A></H3> <div><table width="100%" id="accTable-1"></table>&nbsp;</div> <H3><A href="#accordion-2">Tab 1 Accordion 3</A></H3> <div><table width="100%" id="accTable-2"></table>&nbsp;</div> </div> </div> <div id="tabs-2"> <div id="accordion-2"> <H3><A href="#accordion-3">Tab 2 Accordion 1</A></H3> <div><table width="100%" id="accTable-3"></table>&nbsp;</div> <H3><A href="#accordion-4">Tab 2 Accordion 2</A></H3> <div><table width="100%" id="accTable-4"></table>&nbsp;</div> <H3><A href="#accordion-5">Tab 2 Accordion 3</A></H3> <div><table width="100%" id="accTable-5"></table>&nbsp;</div> </div> </div> <div id="tabs-3"> <div id="accordion-3"> <H3><A href="#accordion-6">Tab 3 Accordion 1</A></H3> <div><table width="100%" id="accTable-6"></table>&nbsp;</div> <H3><A href="#accordion-7">Tab 3 Accordion 2</A></H3> <div><table width="100%" id="accTable-7"></table>&nbsp;</div> <H3><A href="#accordion-8">Tab 3 Accordion 3</A></H3> <div><table width="100%" id="accTable-8"></table>&nbsp;</div> </div> </div> </DIV> <link type="text/css" href="/test/English/Javascript/jQueryUI/jquery-ui-1.7.2.custom.css" rel="stylesheet" /> <script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="/test/English/Javascript/jQueryUI/jquery-ui-1.7.2.custom.min.js"></script> <script type="text/javascript"> // Array of all fields - format: accordionID|FieldInternalName arrTabAccordion = ['0|Title','0|Dummyfield1','0|Dummyfield2', '1|Dummyfield3','1|Dummyfield4','1|Dummyfield5', '2|Dummyfield6','2|Dummyfield7','2|Dummyfield8', '3|Dummyfield9','3|Dummyfield10','3|Dummyfield11', '4|Dummyfield12','4|Dummyfield13','4|Dummyfield14', '5|Dummyfield15','5|Dummyfield16','5|Dummyfield17', '6|Dummyfield18','6|Dummyfield19','6|Dummyfield20', '7|Dummyfield21','7|Dummyfield22','7|Dummyfield23', '8|Dummyfield24','8|Dummyfield25','8|Dummyfield26']; // Initiate all the fields fields = init_fields(); // Add the "tabs" to the formtable $("#tabs").insertAfter('.ms-formtable').tabs(); // Add accordion $("#accordion-1").accordion({autoHeight: false,animated: false}); $("#accordion-2").accordion({autoHeight: false,animated: false}); $("#accordion-3").accordion({autoHeight: false,animated: false}); // Loop trough all fields and move them to the right accordion section $.each(arrTabAccordion,function(idx,item){ var split = item.split('|'); var accID = split[0]; var fieldName = split[1]; if(fields[fieldName]!=undefined){ currField = $(fields[fieldName]); currField.appendTo('#accTable-'+accID); } }); // Fix IE8 issue with zoom $(".ui-accordion-content").css({'zoom':1,'padding':'0px'}); // function - to make "object" of all tr's in the form function init_fields(){ var res = {}; $("td.ms-formbody").each(function(){ if($(this).html().indexOf('FieldInternalName="')<0) return; var start = $(this).html().indexOf('FieldInternalName="')+19; var stopp = $(this).html().indexOf('FieldType="')-7; var nm = $(this).html().substring(start,stopp); res[nm] = this.parentNode; }); return res; } </script>
This is the same code, but added two fields to tab-2, outside the accordion:
<!-- Date field text size --> <style type="text/css"> .ms-dtinput,.ms-dttimeinput{ font-size:0.7em; } </style> <DIV id="tabs"> <UL style="font-size:12px"> <LI><A href="#tabs-1">Tab 1</A></LI> <LI><A href="#tabs-2">Tab 2</A></LI> <LI><A href="#tabs-3">Tab 3</A></LI> </UL> <div id="tabs-1"> <div id="accordion-1"> <H3><A href="#accordion-0">Tab 1 Accordion 1</A></H3> <div><table width="100%" id="accTable-0"></table>&nbsp;</div> <H3><A href="#accordion-1">Tab 1 Accordion 2</A></H3> <div><table width="100%" id="accTable-1"></table>&nbsp;</div> <H3><A href="#accordion-2">Tab 1 Accordion 3</A></H3> <div><table width="100%" id="accTable-2"></table>&nbsp;</div> </div> </div> <div id="tabs-2"> <table cellpadding="0" cellspacing="0" id="tabs-2-table"></table> <div id="accordion-2"> <H3><A href="#accordion-3">Tab 2 Accordion 1</A></H3> <div><table width="100%" id="accTable-3"></table>&nbsp;</div> <H3><A href="#accordion-4">Tab 2 Accordion 2</A></H3> <div><table width="100%" id="accTable-4"></table>&nbsp;</div> <H3><A href="#accordion-5">Tab 2 Accordion 3</A></H3> <div><table width="100%" id="accTable-5"></table>&nbsp;</div> </div> </div> <div id="tabs-3"> <div id="accordion-3"> <H3><A href="#accordion-6">Tab 3 Accordion 1</A></H3> <div><table width="100%" id="accTable-6"></table>&nbsp;</div> <H3><A href="#accordion-7">Tab 3 Accordion 2</A></H3> <div><table width="100%" id="accTable-7"></table>&nbsp;</div> <H3><A href="#accordion-8">Tab 3 Accordion 3</A></H3> <div><table width="100%" id="accTable-8"></table>&nbsp;</div> </div> </div> </DIV> <link type="text/css" href="/test/English/Javascript/jQueryUI/jquery-ui-1.7.2.custom.css" rel="stylesheet" /> <script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="/test/English/Javascript/jQueryUI/jquery-ui-1.7.2.custom.min.js"></script> <script type="text/javascript"> // Array of all fields - format: accordionID|FieldInternalName arrTabAccordion = ['0|Title','0|Dummyfield1','0|Dummyfield2', '1|Dummyfield3','1|Dummyfield4','1|Dummyfield5', '2|Dummyfield6','2|Dummyfield7','2|Dummyfield8', '3|Dummyfield9','3|Dummyfield10','3|Dummyfield11', '4|Dummyfield12','4|Dummyfield13','4|Dummyfield14', '5|Dummyfield15','5|Dummyfield16','5|Dummyfield17', '6|Dummyfield18','6|Dummyfield19','6|Dummyfield20', '7|Dummyfield21','7|Dummyfield22','7|Dummyfield23', '8|Dummyfield24','8|Dummyfield25','8|Dummyfield26']; arrTab = ['1|FieldInTab1','1|FieldInTab2']; // Initiate all the fields fields = init_fields(); // Add the "tabs" to the formtable $("#tabs").insertAfter('.ms-formtable').tabs(); // Add accordion $("#accordion-1").accordion({autoHeight: false,animated: false,collapsible: true,active: false}); $("#accordion-2").accordion({autoHeight: false,animated: false,collapsible: true,active: false}); $("#accordion-3").accordion({autoHeight: false,animated: false,collapsible: true,active: false}); // Loop trough all fields and move them to the right accordion section $.each(arrTabAccordion,function(idx,item){ var split = item.split('|'); var accID = split[0]; var fieldName = split[1]; if(fields[fieldName]!=undefined){ currField = $(fields[fieldName]); currField.appendTo('#accTable-'+accID); } }); // Loop trough all fields and move them to the right tab $.each(arrTab,function(idx,item){ var split = item.split('|'); var tabID = split[0]; var fieldName = split[1]; if(fields[fieldName]!=undefined){ currField = $(fields[fieldName]); currField.appendTo('#tabs-2-table'); } }); // Fix IE8 issue with zoom $(".ui-accordion-content").css({'zoom':1,'padding':'0px'}); // function - to make "object" of all tr's in the form function init_fields(){ var res = {}; $("td.ms-formbody").each(function(){ if($(this).html().indexOf('FieldInternalName="')<0) return; var start = $(this).html().indexOf('FieldInternalName="')+19; var stopp = $(this).html().indexOf('FieldType="')-7; var nm = $(this).html().substring(start,stopp); res[nm] = this.parentNode; }); return res; } </script>
This example is setup in a custom list with 26 single line text fields (Dummyfield1-26).
I have stripped off everything related to selecting the correct tab or accordion on form validation.
I may update this code later.
Regards
Alexander
Alexander,
This works great! You are a life safer! Thanks a ton for figuring this out. My final questions to wrap this job up (I hope) are 1. how do you collapse all the accordions to start, 2. is there a way to keep multiple open, and 3. I need to add a few lines without an accordion inside of the same tab (preferably above the accordion). I have added the $.each(arrTab,function(idx,item) function and put arrTab fields back in. They are invisible! Man you are a huge help and you probably saved me a ton of work this weekend! Cheers!
The accordion and tabs are created using a jQuery UI widget. Read about it here: http://jqueryui.com
Question 1 is answered like this (replace line 67-69):
Alexander
Thanks for the answer to question 1. I figured it was easy. I got confused the first time I looked through that site but it makes a little more sense now. I guess I am left with question 3. Thanks again!
See updated code, have a nice weekend.
Alexander
I may have figured out question 3. I added before the accordion. Thanks again!
Nevermind that last comment that didn’t work.
Alexander,
I just want to thank you again for your help. You saved me a tremendous amount of time and it looks better than I could have imagined. It’s not over yet, but you have helped me jump over some major hurdles. I continue to scour your blog for other tips that will help me make this even better and I keep finding things that help. One thing I might be missing or I can suggest is how to translate some of the things on the jquery site to be useful in Sharepoint. For instance, the options on accordions (arrow icons specifically). How to I use the code on that site in the templates you give? I’ve tried to model something off of the collapsible code you provide above but I can’t get it to work. I’ve learned a lot in a short time and I keep learning. Thanks again!
All the code from http://jqueryui.com/demos/accordion/ can be used in this example.
The accordions are made in line 67-69 in the topmost codeblock, edit like this:
Alexander
Alexander,
Thanks for the response as always. It seems simple enough but I can’t get it to work. I added the var code and then the icons:icons part and nothing happens. Also the hardest part for me is going to that other site and then seeing what you give me and matching them up. I’m totally new at this kind of code so it’s probably some elementary concepts I’m still learning. Thanks a ton man! So far everyone likes what has come out of this project. It seems like I live on your site scouring for improvements and I keep finding things. Keep it up!
Alexander,
I saw in your post about tabs a few people ask about “duplicating” fields inside of other tabs. I didn’t see a definitive answer on how to do it. I looked on the site about cloning but that didn’t make any sense to me. I need certain duplicate columns inside of the accordions which are inside of the tabs. I tried to just put the FieldInternalName in again where I wanted it with the correct accordion number but it didn’t do anything. I need these for all three forms. Thanks in advance man!
Hi,
Duplicating fields in NewForm or EditForm is not possible because it will confuse SharePoint on save item (duplicated field id).
You would have to move them between tabs/accordions with some custom code.
In DispForm it is no problem, just clone the field and insert it in multiple tabs/accordions.
Alexander
Alexander,
Thanks for the response. I understand how it could conflict if there were two places to enter. I guess I was hoping to just display the field in two places and just have it reflect once what has been entered. I kinda had it do this when I was having trouble getting the code you eventually came to in this tutorial. It was not by design of course but I was showing the same fields in two accordions. If I entered something in the one accordion and it would show what I had entered when I went to the next one. I’m not sure how I did it. It could have been a total fluke but that’s what I am hoping for. And by custom code I guess you mean it’s difficult to have a general rule or template that could accomplish this? Thanks a lot. Have a great day.
Alexander,
I know you’ve been busy. I was just wondering if you had any thoughts from my last post here. I’m presenting my site in the next couple of days and I would like to have this in the works if possible. Thanks as always!
Alexander,
Any thoughts on this? I’d really like to find a way to make this happen. Thanks!
Hi,
I have modified the code to allow cloned elements, but note: This is cloning a field and therefore you must test it’s behavior. My quick test shows that a cloned text field will concatenate the values from both inputs, but test it and expect problems…
The bits changed are as follows (line numbers refers to the bottom code section):
You can now add a field to multiple tabs by referring it multiple times in the variable “arrTabAccordion”.
Alexander
Alexander,
Thanks for the response! I have tried to manipulate what you said a few ways and can’t get it to work. Would you mind telling me where I’m going wrong? I apologize for the lengthy code. Thanks so much!!!!
I am trying to duplicate Established Zirconization for this test. I accidentally posted it twice in slot 1 (now fixed in the code on my site). It currently shows in slot 7 once accepted but the clone will not show in slot 1. Thanks a bunch!
Sorry again it’s Zirconization Competitor to be cloned.
In your code – line 95 – you have missed my updated code from my comment above.
Alexander
Alexander,
Thanks! That worked. I was putting it in the wrong place. Now that I tried it, I see why you say it won’t work. It duplicates the entries. It does accept them at least! But when you go to edit the item and the fields both have entries it duplicates it every time so you end up with a bunch of duplications. Thanks so much for your help. I knew you’d show me a way to get it to work. I just wanted to see what it would do and if it would help. Unfortunately it won’t. Thanks for making it work for me! You can see I’ve used a ton of what you’ve offered (even more than the above code). Keep it up!