29.01.2012 I have done some work during this weekend, and i see that i have underestimated the complexity dealing with other than “is equal to” in this solution. I will see what i can do about that, and will post a new version as soon as i can manage. In the meantime, stick with “is equal to”.
Please note that this solution is under development – and is still BETA. I’m almost certain I’ll have to change the configuration options – and this will break the existing “filters”. Please bear this in mind when testing this solution.
Alexander
22.01.2012
I have redone the script due to some bugs in the initial release. It should still be considered as a “beta”, but i hope as many as possible can test it and let me know the result.
I have not added any functionality over the initial release as i want to ensure the parts already in it works as expected before doing so. I have however noted these requests:
- DispForm support
- Set field value / clear field value
Alexander
I posted a teaser for my latest project in December. Now I thought it was time to post a working solution!
This solution will let you add dependent logic to your forms.
For example you could have a Yes/No check box determines whether some fields as required or not, or the status selector in a Tasks list can toggle which fields are visible or read only when you change from “In progress” to “Completed”.
Please note that the initial release is set to v0.9. I expect you to find some bugs! Please test it and comment below if you find something wrong, or you have a feature request.
All screenshots are from SharePoint 2010, but this solution is designed for both SharePoint 2007 and SharePoint 2010. I have tested it in IE7, IE9, FireFox 9.0.1 and Google Chrome 16.0.912.75.
Download the file “DynamicFormsForSharePoint.js” and “spjs-utility.js” from here. Please note that you will need the version dated 18.01.2012 or newer of “spjs-utility.js”. You find the files in folders with corresponding names. You also need jQuery – download i here. You may use the latest version, but i prefer v1.6.4 as it is faster in some areas. Please note that not all of my other solutions will work with jQuery v1.7x.
Put these files in a document library or a folder created with SharePoint Designer. Ensure all users have read access to this location.
This solution is set up by referring a script from NewForm and EditForm of the lists where you want the solution activated.
Add a CEWP to NewForm and EditForm like this
SharePoint 2007
Go to NewForm and EditForm and edit the URL by adding toolpaneview=2 behind the URL in this format:
…/NewForm.aspx?toolpaneview=2
…/EditForm.aspx?ID=12&toolpaneview=2Press Enter and you should be able to add a CEWP to the page. Put the CEWP below the form web part.
SharePoint 2010
In the list view, click “List” on the List Tools menu. Then select “Form Web Parts” and pick NewForm and Editform from there and add a CEWP to the page. Put the CEWP below the form web part.
I recommend using the Content link option in the CEWP to refer the code like the example below. The CEWP code should be put in a text file (txt) or an aspx file like in the example below. This file should be put in the same location as you put the file “DynamicFormsForSharePoint.js”. You could also put the code directly in a HTML Form web part as this web part is handled in a slightly different manner in SharePoint 2010, and therefore does not mess with the script generated HTML.
The code the file CEWP.js.aspx
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript" src="/test/Scripts/DynRequired/spjs-utility.js"></script> <script type="text/javascript" src="/test/Scripts/DynRequired/DynamicFormsForSharePoint.js"></script>
You must change the script src to all files so that they refer your local files.
These three scripts are all that goes in the CEWP – all configuration is done in a graphical user interface.
When this solution is first setup in a site, the configuration list is created automatically. This list is not to be hand edited, and it can be hidden using SharePoint Designer if you like.
When you configure the solution for a specific NewForm or EditForm, the configuration is stored using the site-relative URL of the form as an identifier. When a user loads the form in a browser, this configuration is read from this location and the rules are applied “on the fly”.
Note:
When manipulating required fields, you must NOT set the fields as required under list settings in SharePoint. Let this script handle it.
When the solution is set up, the only thing giving it away is the little version number in the bottom left corner of the form:

You click this version number to enter the configuration. Note that this version number is visible only if the solution has not yet been set up, or the logged in user is the one that configured the solution for this particular form in the first place.
You can however enter the edit mode manually by appending to the URL like this:NewForm.aspx?setup=1 or EditForm.aspx?ID=10&setup=1
If you set up a password protection for the configuration, you are prompted for the password when entering the edit mode:

This dialog is bypassed if there are no password.
You then enter the configuration:

You can use these field types as “triggers”:
Yes/No, Drop-Down Menu, Radio Buttons, Checkboxes (allow multiple selections) and Single line of text.
You can use the following operators to match their value
- is equal to
- is not equal to
- is greater than
- is less than
- is greater than or equal to
- is less than or equal to
- begins with
- contains
This configuration will result i these changes to the form

Let me know if you get this solution working. I’ll update the article with any missing parts tomorrow, so please let me know if you find any bugs in the solution, or missing steps in the article.
Alexander




January 19, 2012 at 3:08 am |
Brilliant work, Alex.
January 19, 2012 at 2:38 pm |
Your amazing!
Got it installed and working WSS3.0 so far so good, I will let you know if I run into any issues but the install went easy with your instructions.
January 19, 2012 at 3:45 pm |
Just wondering, how will this work with the display form?
January 19, 2012 at 4:03 pm
There are no DispForm functionality in the current release. I’ll introduce that as soon as I see that the NewForm / EditForm parts work as they should.
Alexander
January 19, 2012 at 3:57 pm |
Hi Alexander,
I put this in place on a custom New form and the configuration GUI pops up, but there are no fields listed in the drop down box to configure. Any suggestions? I am on SP2007 and copied all of the js files to a local shared directory.
January 19, 2012 at 4:04 pm
The problem is the customized form. This solution is designed for “out of the box” SharePoint forms.
Alexander
January 19, 2012 at 4:41 pm
That’s pretty much what I figured
. Reverted to default ‘New’ form and worked perfectly. Thanks for yet another outstanding solution. If anyone out there hasn’t bought Alexander a beer yet….you really should.
One possible thing to look into, I am using a drop down box as the trigger and every once in a while if I change the drop down back and forth between options, it seems to ‘forget’ the hidden fields. Not constant and doubtful a user would use the form that way (i switched like 8 times in a row).
January 19, 2012 at 4:45 pm
Follow up to the drop down issue…I have three options, blank, opt1, opt2, with blank being the default. I configured it to hide all fields when blank and show/hide depending on the other two selections. When creating a new item, it does hide all fields. When switching from opt1 to opt2, it works fine but switching from opt1 or opt2 back to blank, all fields show.
January 19, 2012 at 4:45 pm
Hi,
Glad you got it working. Thanks for the feedback on the dropdown menu. I’ll look into it.
Alexander
January 19, 2012 at 4:26 pm |
Hi Alexander,
I have this instsalled in 2010 in a custom list, but using OOTB forms, and I am having the issue where no fields are showing up in the first drop down to configure. I have everything setup with the right version numbers.
January 19, 2012 at 4:28 pm |
I see the issue. It’s just like you said in your previous reply…custom lists won’t work. I got this working with a simple tasks list.
Thanks!
January 19, 2012 at 4:34 pm
The SharePoint list type “Custom List” will work, but only if you have not tampered with it in SharePoint designer.
If the list is “Original SharePoint”, you could send me some screenshots of the setup and I’ll see if i can find out what’s wrong.
Alexander
January 19, 2012 at 4:56 pm |
Alexander,
Thanks so much. I saw my error in the Custom List and got it working. This solution is sweet. I look forward to seeing the additions for the Dispform. The new and edit forms work perfectly for me!
Erich
January 19, 2012 at 7:17 pm
I just noticed that the logic doesn’t seem to be working in 2007 with choice fields setup with radio buttons. If I switch to a drop down, then thing work great. Just an FYI…
January 19, 2012 at 5:57 pm |
hey, great work once again.
just to flood you with more requests – i wonder if there’s an easy way to pre-select one line in a choice field.
this basic functionality, that was so easy done in html with “selected”, is somehow not avail in sharepoint :/
would be cool if you find time and might add this to your script, e.g. if cluster = active_directory then meeting = ad_meeting else if ..
January 20, 2012 at 8:45 am |
Great solution!
So far seems to be working as advertised
I was wondering, if it would be possible to have an option to clear the values of some fields.
Here is a possible minor problem with the current solution:
Leaves the “Not started” option turned on, fills some fields and then decides to change the option to “In progress” and fills in other fields. All the fields get saved. I can imagine how in some solutions this might be a bit of a problem.
But hanks for the great job! This will be very useful solutin!
January 20, 2012 at 3:04 pm |
[...] Pues esto es lo que propone Alexander en su blog. Les dejo el enlace: http://sharepointjavascript.wordpress.com/2012/01/19/dynamic-forms-for-sharepoint/ [...]
January 23, 2012 at 12:49 am |
Hi all,
The solution is updated. Please try out v0.9.1 and let me know if it behaves as expected.
Alexander
January 23, 2012 at 4:11 pm |
First of all: EXCELLENT solution! Absolute must-have!
However, I cannot get it to run: the version number does not appear on my 2007 box. I can however enter the configurationscreen using ?setup=1. After I enter an empty password, I get an error:
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.2; .NET4.0C; .NET4.0E)
Timestamp: Mon, 23 Jan 2012 14:04:46 UTC
Message: Object expected
Line: 737
Char: 3
Code: 0
URI: http://s4279o:7887/sites/robert/sub1/SiteResources/DynamicFormsForSharePoint.js
Line 737 corresponds to:
res = spjs_addItem({listName:settingsListName,data:{Title:pageId,blob:spjs_stringify(settings)}});
My spjs-utility (dating 30-11-2011) does not contain the method spjs_additem. Could that be the problem?
January 23, 2012 at 4:17 pm
You must update your version of spjs-utility.js to “18.01.2012″ or newer.
Alexander
January 23, 2012 at 4:21 pm |
I just noticed myself there was an update version, ahem. :-S
Anyhow: still no versionnumber. When on the setup-page, being prompted for a password, clicking on Save results in an alert displaying ‘null’.
January 23, 2012 at 4:32 pm
Hi,
Did you test the initial version 0.9, or is v0.9.1 your first attempt?
Alexander
January 23, 2012 at 4:50 pm
I’ll do a test to see that i do not have a bug somewhere. Stay tuned.
Alexander
January 23, 2012 at 4:38 pm |
0.9.1 is my first attempt.
Also, I load both jquery (1.6.4) and spjs-utility from my masterpage. spjs-utility is loaded dynamically using $.getScript(L_Menu_BaseUrl + ‘/SiteResources/spjs-utility.js’, …)
Can this be the problem? Elsewhere in this site I use methods from spjs-utility without a problem.
January 23, 2012 at 4:55 pm
Quick test with the published files done with no errors. Are there any other scripts in that particular form that could interfere?
Alexander
January 23, 2012 at 5:37 pm |
Loading the DynamicFormsForSharePoint.js dynamically as well solves all javascript errors.
However, I now get a different error on line 165 of this script. I find this code:
case ‘SPFieldChoice’:
// Load
if(dObj[getFieldValue(fin)]!==undefined){
match = isMatch(obj.operator,getFieldValue(fin),dObj[getFieldValue(fin)].triggerValue);
if(match){
It refers to obj.operator, however I cannot find where obj is initialised. Shouldn’t this be dObj?
January 23, 2012 at 6:04 pm
I have fixed the bug in v0.9.2. Thank you for finding it!
Alexander
January 23, 2012 at 6:57 pm |
I have everthing set. The page shows for the Dynamic Forms for Sharepoint and I’m able to insert criteria. The problem comes when I try and save it. I receive the following:
Line 738
Char: 3
Error: Object Expected
Code:0
I’m the Site Collection Admin and can’t figure out what I’m doing wrong..
Thanks,
Marty
January 24, 2012 at 2:02 am
I also have the latest files…
Marty
January 24, 2012 at 9:33 am
Hi,
Is it SP2007 or 2010? And which browser are you using?
Are you sure you have the latest version of spjs-utility.js?
Alexander
January 24, 2012 at 10:23 am |
Excellent, works perfect now!
Maybe a nice new feature would be to support a rule where a field is set and made read-only. Eg: when adding a new item, status must be forced to ‘New’, or when editing an item, a status field is forced to the next logical status or the list of possible new statusses is limited to a certain set. Current functionality can be used to show only the appropriate fields.
January 24, 2012 at 7:10 pm |
Hi Alex, the “These Fields are Hidden” does not seem to work in conjunction with your AccordianForSharepointForms utility, is that correct or doing something wrong on my end?
Thanks,
Ken
January 24, 2012 at 8:48 pm
Hi,
This solution is designed to work “alone”. I have not tried to make it compatible with any of my existing solutions – that would be nearly impossible as I have posts so many different solutions.
It might be possible to have some of them work together, the problem is that both the accordion solution and this one show and hide fields – thus interfering with each other.
Alexander
January 24, 2012 at 7:22 pm |
Is there a way to recover existing 9.0 rules after moving to 9.2
January 24, 2012 at 7:51 pm
Sorry, but the stored settings have a new format. And due to the beta status, I have not made it backwards compatible. Alexander
January 24, 2012 at 8:21 pm |
Bouncing back and forth between 9.0 and 9.2, same rule in 9.0 working on a dropdown field that is not empty and requiring one visable field and readonly on a hyperlink and multiline text field works but does not once same rule is recreated in 9.2
January 24, 2012 at 8:43 pm
A bit hard to follow your example. Please send me some screenshots so I can recreate the issue.
Alexander
January 24, 2012 at 11:43 pm |
No problem, I understand. Just FYI for others
January 26, 2012 at 12:36 pm |
Very odd, but when trying to use this component on a different (and highly customized) MOSS-environment, I found that it didn’t work at all. Turned out the javascript variable L_Menu_BaseUrl was not available. I fixed this by adding a custom script that adds it, but I have no idea how this is possible.
January 26, 2012 at 4:08 pm
Same issue for L_Menu_LCID.
February 5, 2012 at 6:52 pm
Hi,
Both these variables are part of the master page. It must have been “customized” away – maybe unintentionally.
Alexander
January 26, 2012 at 3:53 pm |
Hello Alexander,
Thank you for your great work with setting up Dynamic Forms, and having a 2007 solution as well. Due to company budget constraints we will not be going to 2010 any time soon. I was wondering if this could be used to track Outlook 2007 emails as well? We need to store all the emails, and their attachments. We also need to be able to have an advanced search option to track down these stored emails and attachments. Thanks for your help.
January 28, 2012 at 1:32 am
Hi,
Sorry, but this solution is intended for the built in SharePoint forms only. I do not have any solutions for handling emails, but you might want to look at this solution which can publish your emails as PDF
Alexander
January 29, 2012 at 6:14 pm |
Hi Alexander,
I have just today copied your files and installed at a SP2010 environment.
(an older solution, mouse over attachment works with an other list, we have mailed sometimes in the past about this issue)
I uploaded the both .js files and the js.aspx file into the same document library, the ja.apsx was changed to contain the links to the above mentioned doclib.
I did not get it wortking. There is no version number shown (lower left edge) after changing New and Edit Forms.
If I add the Setup=1 behind the newform, I get asked for a Password (options save or cancel)
Cancel shows the edit form, but no select options for your script, entering a blank or nothing or a number and clicking on save did not show any changes. The bottom line of IE shows: Errors on page..
Would you please so kind to give me some hints?
Kind Regards
Michael
January 29, 2012 at 6:47 pm
Hi,
What does the error message say other than Error on page?
Alexander
January 29, 2012 at 7:02 pm |
It says:
Details zum Fehler auf der Webseite
Benutzer-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; .NET4.0C)
Zeitstempel: Sun, 29 Jan 2012 16:53:52 UTC
Meldung: Objekt erwartet
Zeile: 634
Zeichen: 2
Code: 0
URI: http://portal-test.xxx.com/PSQ/Java/DynamicFormsForSharePoint.js
in English
Message: Object expected
Line: 634
Characters: 2
Code: 0
URI: http://portal-test.xxx.com/PSQ/Java/DynamicFormsForSharePoint.js
Using your edit sequence EditForm.aspx?ID=10&setup=1 I received the following message:
Error
No item exists at http://portal-test.xxx.com/PSQ/Lists/Dynamic/EditForm.aspx?ID=10&setup=1. It may have been deleted or renamed by another user.
Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator.
Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: 2d3dd471-de51-4f5f-94d3-a5e62243ea0b
Date and Time: 1/29/2012 6:00:16 PM
Sorry that I missed this before, must look how to get this.
Kind regards
Michael
January 29, 2012 at 7:08 pm
Have you updated to the latest version of spjs-utility.js?
Alexander
January 29, 2012 at 7:14 pm
I just no going to reload it, but originally I choosed the 18.01 version
Michael
January 29, 2012 at 7:18 pm
Downloaded form your page, uploaded to SP, Newform edit done….it is still requiring a password
btw: Thanks a lot
Michael
January 30, 2012 at 10:25 am
Still playing around. At the office retested.
Still complains about an missing object at Row 634 and 738 in dynamicform.js. (Code 0)
the L_Menu_BaseUrl is existing and set to “/Sitename” (Without leading http://portal-test.xxx.com ……
Regards Michael
January 30, 2012 at 11:01 am
Switched over to firefox 9.0.1
This Browser said:
Fehler: spjs_QueryItems is not defined
Quelldatei: http://portal-test.xxxx.com/PSQ/Java/DynamicFormsForSharePoint.js
Zeile: 634
and show this line after extending the error
res = spjs_QueryItems({listName:settingsListName,query:qb.join(”),viewFields:['ID','Title','blob']});
I am not able to find this at the spjs-utility.js, only the outgoing call from the dynamic.js (Row 634)
Hope that helps, you ideas are really appreciated, this is THE function my colleagues and me have still missed in the past!
Kind regards
Michael
January 30, 2012 at 1:11 pm
Hi,
The function “spjs_QueryItems” is part of the latest spjs-utility. Please ensure you got the correct one.
Alexander
January 30, 2012 at 5:02 pm
Its running now..but dont me ask why.
Delete all the stuff from yesterday, load down (the same things like yesterday I hope), upload and creat CEWP.txt file.
First it lools like as an Problem with full url: Http.//…..
but not yet. It is working with long and short “Links” to the *.js scripts.
Thanks a lot, now I will start to test the functionality
Kind Regards