none
Enabling sharepoint controls on NewForm.apsx RRS feed

  • Question

  • Hello Friends,

    I have a list which has

    1. Yes/No field

    2. FirstName field.

    Now my requirement is when I select the "yes" option then the "FirstName" field should be enabled. How can I achieve this functionality?

    Please suggest


    Thanks & Regards, Chandra Shekhar
    Wednesday, December 14, 2011 9:09 AM

Answers

  • Hi Shekhar R,

    You can use JavaScript(or JQuery) to achieve the goal.

    <script src="http://server/JQueryLib/jquery-1.6.1.min.js"></script>
    <script>
    $(document).ready(function(){
    var hidden = true;
    $('input[title="FirstName"]').parent().parent().parent().hide();
    $('input[title="ShowFirstName"]').change(function(){

    if(hidden )
    {
    $('input[title="FirstName"]').parent().parent().parent().show();
    hidden = false;
    }
    else
    {
    $('input[title="FirstName"]').parent().parent().parent().hide();
    hidden = true;
    }

    });
    });
    </script>

    FirstName: it is the name of the FirstName field in this case.
    ShowFirstName: it is the name of Yes/No field.
    http://server/JQueryLib/jquery-1.6.1.min.js: it is a link to a JQuery file that is stored in a library.

    You can use Content Editior web part or HTML form web part to add the JavaScript into the NewForm.aspx(http://server/Lists/<listNameHere>/NewForm.aspx) page.

    If there is anything unclear, please feel free to ask.

    Thanks,
    Jinchun Chen


    Jinchun Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)
    Thursday, December 15, 2011 10:33 AM
    Moderator

All replies

  • Hi Chandra,

    Do you have the enterprise version of SharePoint 2010? If so, you can use InfoPath to do this.  Make sure you have InfoPath 2010 installed on your computer, then go to the List tab in the ribbon.  Click the big purple button to Customize the form with InfoPath.  With this, you can use conditional formatting (rules)  to show and hide any parts of the form according to conditions.


    Krishana Kumar http://mosstechnet-kk.com
    Wednesday, December 14, 2011 9:29 AM
  • Hello,

    Well I need to accomplish this without Infopath.


    Thanks & Regards, Chandra Shekhar
    Wednesday, December 14, 2011 9:46 AM
  • Ok, then if you Modifying the Out Of the box NewForm.aspx might not be a good idea... future moss updates(or hotfixes ) can override your changes. 

    Alternatively you can create your own NewListForm.aspx and use it ( you can achive the same look and feel of the OOTB NewForm.aspx by applying required sytles)

     Create your own ASPX page to render the form, and place this in 14\Template\Pages

    Place code-behind for your ASPX page and write the logic  for your show hide control based on the conditions

    Create your own list definition

    In the schema.xml of your list definition, override the Setup Path for the New Form element to point at your custom ASPX page

     

    • Edited by KRISHANA KUMAR Wednesday, December 14, 2011 11:46 AM spell check
    Wednesday, December 14, 2011 11:20 AM
  • Hi Shekhar R,

    You can use JavaScript(or JQuery) to achieve the goal.

    <script src="http://server/JQueryLib/jquery-1.6.1.min.js"></script>
    <script>
    $(document).ready(function(){
    var hidden = true;
    $('input[title="FirstName"]').parent().parent().parent().hide();
    $('input[title="ShowFirstName"]').change(function(){

    if(hidden )
    {
    $('input[title="FirstName"]').parent().parent().parent().show();
    hidden = false;
    }
    else
    {
    $('input[title="FirstName"]').parent().parent().parent().hide();
    hidden = true;
    }

    });
    });
    </script>

    FirstName: it is the name of the FirstName field in this case.
    ShowFirstName: it is the name of Yes/No field.
    http://server/JQueryLib/jquery-1.6.1.min.js: it is a link to a JQuery file that is stored in a library.

    You can use Content Editior web part or HTML form web part to add the JavaScript into the NewForm.aspx(http://server/Lists/<listNameHere>/NewForm.aspx) page.

    If there is anything unclear, please feel free to ask.

    Thanks,
    Jinchun Chen


    Jinchun Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff AT microsoft.com(Please replace AT with @)
    Thursday, December 15, 2011 10:33 AM
    Moderator