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 31, 2012 at 3:04 pm |
Hi Alex,
I installed 0.92 yesterday and this is an amazing tool you solved a big issue i was facing! I have 1 observation and 1 suggestion.
After installing the webpart the list fields weren’t populating in the setup screen. I had to move the CEWP below the form for it to work. You may want to add that to your instructions.
Also as a suggestion adding functionality to set properties based on multiple fields would be very usefull. i.e. If field a= 1 and field b = 2 then field c is required.
January 31, 2012 at 4:40 pm |
Hi Alex,
Is there someway i can get this to work in conjunction with your tabs for forms solution?
I’ve added to the same form below the dynamic forms CEWP and removed the jquery referrance but its not working…
Thanks in advance.
February 1, 2012 at 1:36 pm
Nevermind. I got this working with the accordion display. This is actually an amazing combo!
I have the dynamic forms set to a status field which makes other fields required. Based on the status chosen the required fields appear below the status box. It’s perfect!
February 3, 2012 at 1:03 am
Hi, another awesome awesome solution!
I also tried to combine this with the Tabs for Forms scripts and it doesn’t work completely. Hiding and showing fields does work, and the “required field” red asterisk shows up, but the form submission doesn’t enforce the required fields.
February 9, 2012 at 11:37 pm
Hi,
Not without modifying one or both scripts. Take a look at the “PreSaveItem” and / or “PreSaveAction” – those cannot be added twice and must be merged from the two solutions. You cannot have the dynamic forms solution hide fields either – as this would conflict with the showing and hiding of fields in the tabs solution.
Please note that this solution is in BETA and as I have a lot of comments to answer and old solutions that need updating, it may take a while before i can get this one out of BETA.
Alexander
February 1, 2012 at 9:46 pm |
[...] Dynamic Forms for SharePoint [...]
February 1, 2012 at 9:47 pm |
[...] Dynamic Forms for SharePoint [...]
February 3, 2012 at 7:32 pm |
Alex,
I have installed the CEWP and code and doble checked the js references to the 3 .js files. When I click to initialize the solution I get the configuration screen but recieve an error on the page when I attempt to save my rule or rules.
The error details are:
Line 739 Char 3 Error Object expected Code 0
Any Ideas?
February 3, 2012 at 7:56 pm
Have you updated “spjs-utility.js” to the latest version?
Alexander
February 4, 2012 at 12:45 am |
DynamicFormsForSharePoint.js
Line 271 Char2 Error Object expected Code 0
DynamicFormsForSharePoint.js
Line 739 Char 3 Error Object expected Code 0
Any Ideas?
February 6, 2012 at 5:45 pm |
That was my main issue. I had grabbed the Nov release accidentally.
February 6, 2012 at 8:58 pm |
Thanks so much Alexander – this will be a life saver, along with several other solutions from your site!
I am having one issue – I have a multiple lines of text field set to be displayed and required when my dropdown is equal to “Complete”. For all other options in the dropdown, the field is hidden. The field hide/reveal functionality works fine. However, I am still able to save the item without entering in any text in the text box (as in the field is not truly required).
I would expect to be unable to save without completing this field. Is there some kind of configuration setting that I am missing?
February 10, 2012 at 12:33 am
Hi,
SP2007 or 2010? – rich text or plain text? Any other scripts interfering?
Alexander
February 23, 2012 at 2:13 am
Hi! Sorry – I didn’t see that you had replied. I’m in SP2010. Per your prompt, I changed the field to Plain Text and the required field worked great.
Thanks again for your site – you have helped me extensively!
February 7, 2012 at 3:37 pm |
Simply just perfect Alexander! Thank you!
February 14, 2012 at 12:20 pm |
Great job! Made my life a lot easier!
February 14, 2012 at 5:41 pm |
I have an idea for this to really top it off.
Can you implement a way to add multiple values (an array) in the “This value” field so that when using a dropdown we have more flexability in our logic?
February 23, 2012 at 11:26 pm |
Hi Alexander,
Great site.
I’m having a hard time getting your Dynamic Forms working. I’m on SharePoint 2010, using dynamicforms script 092 and spjs-util from Jan 18-12.
I had a custom New form but I’ve reverted to the unedited original NewForm.aspx.
Using IE Developer Tools debugger, the error I get is ” ‘$’ is undefined “.
The line it’s breaking at is line 186 in spjs-util file, shown here:
–> $.fn.filterNode = function(name) {
return this.find(‘*’).filter(function() {
return this.nodeName === name;
});
};
This may be an easy answer, but I’m fairly new to js. Thanks for your help.
Martin
February 25, 2012 at 1:28 am
Ensure the path to jQuery is correct.
Alexander
February 24, 2012 at 9:28 am |
Hi alex
Thank you very much for this script. It is working perfectly. Just when i set a “Multi-Line Rich-Text” Field as required a did not get a error message, i just get the red star by the filed but i can save the form without any text in the multi-line rich text field. Other fields like date-fields are working.