Stump the Panel » End Users and Information Workers

Interactively hiding fields in NewForm and EditForm

(8 posts)
  1. ericsd
    Member

    Is there a way to script fields on the NewForm or EditForm to interactively show or hide fields based on user selections? I was thinking this could be done with JQuery (1st choice - available to all site owners) or script added through SPD (2nd choice - limited availability).

    Thanks!

    Posted 1 month ago #
  2. @ericsd

    Are you looking for something like an expand/collapse for each field?

    Posted 1 month ago #
  3. ericsd
    Member

    I was thinking that if I had the following columns in a list:
    Item (choice): Burger; Sandwich
    Meat Temperature (choice): Rare, Medium-Rare, Medium, Medium-Well, Well
    Pickles (choice): Yes, No
    Type of Meat (choice): Roast Beef, Grilled Chicken, Turkey
    Type of Bread (choice): White, Wheat, Sourdough

    That if the user picked Burger for the item, then the meat temperature and pickles fields would show and the last two be hidden. Or if the user picked Sandwich, the opposite will happen.

    I know I can create a Burger content type and a Sandwich content types but the desire is to have dynamic forms as can be done in Infopath but using lists.

    Thanks!

    Posted 4 weeks ago #
  4. n2nature
    Member

    I have no solution but would like to accomplish the same idea.

    Posted 4 weeks ago #
  5. I came across this link the other day. I have not used it myself so have no idea if it is any good or not but it certainly implies that it would resolve your issue:

    http://www.soft32.com/download_230829.html

    Let me know how you get on!

    Posted 4 weeks ago #
  6. What about if you create the two content types and add a link to your form that allows you to switch between the two. &ctxType= ... or something like that will need to be appended to your EditForm.aspx url.

    Posted 4 weeks ago #
  7. tecrms
    Member

  8. jaxkookie
    Member

    I combined to scripts to get somehting close to what you are looking for. I us a check box in my script, but I am sure it would not take much to modify for your use
    The hidefiles was an existing script That you can find almost any where on the net.

    <script language="JavaScript" type="text/javascript">
    _spBodyOnLoadFunctionNames.push("hideFields");
    
    function findacontrol(FieldName) {
       var arr = document.getElementsByTagName("!");//get all comments
       for (var i=0;i < arr.length; i++ )
       {
          // now match the field name
          //if (arr[i].innerHTML.indexOf(FieldName) > 0) {
    	  if (arr[i].innerHTML.indexOf('FieldName="' + FieldName + '"') > 0) {
             return arr[i];
          }
       }
    }
    
    function hideFields() {
       var control;
    if (document.forms[0].click.checked == true) {
    //alert('Help');
            control = findacontrol("Start Date");
            control.parentNode.parentNode.style.display="none";
            control = findacontrol("End Date");
    		control.parentNode.parentNode.style.display="none";
            control = findacontrol("Priority");
    		control.parentNode.parentNode.style.display="none";
    control = findacontrol("CalID");
    control.parentNode.parentNode.style.display="none";
    	}
    else {
    	control = findacontrol("Start Date");
            control.parentNode.parentNode.style.display="inline";
            control = findacontrol("End Date");
    		control.parentNode.parentNode.style.display="inline";
            control = findacontrol("Priority");
    		control.parentNode.parentNode.style.display="inline";
    control = findacontrol("CalID");
    control.parentNode.parentNode.style.display="inline";
    	}
    
    }
    </script>
    <input type="checkbox" id="click" name="click" onClick="hideFields();" checked>
    Posted 3 weeks ago #

RSS feed for this topic

Reply

You must log in to post.