Dynamic Forms for SharePoint


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:

  1. DispForm support
  2. 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.

How to set it up

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=2

Press 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.

CEWP setup in SharePoint 2010
IMG

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.

Behind the scenes

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”.

How to configure the solution

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:
IMG
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:
IMG
This dialog is bypassed if there are no password.

You then enter the configuration:
IMG

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
Example

The Configuration
IMG

This configuration will result i these changes to the form
IMG

IMG

IMG


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

104 Responses to “Dynamic Forms for SharePoint”

  1. Charlie Epes Says:

    Brilliant work, Alex.

  2. Ken Says:

    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.

  3. Erich Says:

    Just wondering, how will this work with the display form?

    • Alexander Bautz Says:

      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

  4. JeffG Says:

    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.

    • Alexander Bautz Says:

      The problem is the customized form. This solution is designed for “out of the box” SharePoint forms.

      Alexander

    • JeffG Says:

      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).

    • JeffG Says:

      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.

    • Alexander Bautz Says:

      Hi,
      Glad you got it working. Thanks for the feedback on the dropdown menu. I’ll look into it.

      Alexander

  5. Erich Says:

    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.

  6. Erich Says:

    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!

    • Alexander Bautz Says:

      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

  7. Erich Says:

    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

    • Erich Says:

      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…

  8. jan Says:

    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 ..

  9. soikins Says:

    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!

  10. Pantallas dinámicas en #Sharepoint - JUAN PABLO PUSSACQ LABORDE Says:

    [...] 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/ [...]

  11. Alexander Bautz Says:

    Hi all,
    The solution is updated. Please try out v0.9.1 and let me know if it behaves as expected.

    Alexander

  12. Robert Says:

    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?

    • Alexander Bautz Says:

      You must update your version of spjs-utility.js to “18.01.2012″ or newer.

      Alexander

  13. Robert Says:

    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’.

  14. Robert Says:

    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.

    • Alexander Bautz Says:

      Quick test with the published files done with no errors. Are there any other scripts in that particular form that could interfere?

      Alexander

  15. Robert Says:

    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?

  16. Marty Says:

    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

  17. Robert Says:

    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.

  18. Ken Says:

    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

    • Alexander Bautz Says:

      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

  19. Ken Says:

    Is there a way to recover existing 9.0 rules after moving to 9.2

    • Alexander Bautz Says:

      Sorry, but the stored settings have a new format. And due to the beta status, I have not made it backwards compatible. Alexander

  20. Ken Says:

    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

    • Alexander Bautz Says:

      A bit hard to follow your example. Please send me some screenshots so I can recreate the issue.
      Alexander

  21. Ken Says:

    No problem, I understand. Just FYI for others

  22. Robert Says:

    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.

  23. Mike Says:

    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.

  24. Michael Says:

    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

  25. Michael Says:

    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

    • Alexander Bautz Says:

      Have you updated to the latest version of spjs-utility.js?

      Alexander

    • Michael Says:

      I just no going to reload it, but originally I choosed the 18.01 version
      Michael

    • Michael Says:

      Downloaded form your page, uploaded to SP, Newform edit done….it is still requiring a password
      btw: Thanks a lot :)

      Michael

    • Michael Says:

      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

    • Michael Says:

      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

    • Alexander Bautz Says:

      Hi,
      The function “spjs_QueryItems” is part of the latest spjs-utility. Please ensure you got the correct one.

      Alexander

    • Michael Says:

      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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 435 other followers