CRM Open Source Business & Social CRM Software

Results 1 to 4 of 4

Thread: HOWTO: Conditionally required field - on the fly

  1. #1
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,266

    Default HOWTO: Conditionally required field - on the fly

    Here's how to have a conditionally required field. In this case we want a date field called date_golive_c to be required if a checkbox called transitioned_c is checked. If it gets unchecked we want it to not be required. This requires altering the editviewdefs.php in custom/modules/YOURMODULE/metadata. Good luck!

    PHP Code:
                array (
                  
    'name' => 'transitioned_c',

    /** [IC] eggsurplus: 2008/12/16 - make date_golive_c required if user checks the checkbox */
                  
    'customCode' => '
    {literal}
    <script language="javascript">

    function requireGolive(transChecked) {
        //need to iterate to find the correct index
        for(var i = 0; i < validate["EditView"].length; i++){
            if(validate["EditView"][i][nameIndex] == "date_golive_c") {
                if(transChecked == true) {
                    validate["EditView"][i][requiredIndex] = true;
                    alert("Please fill in the Go-Live Date.");
                } else { //do not require
                    validate["EditView"][i][requiredIndex] = false;
                }
                break;
            }
        }
    }
    </script>
    {/literal}
                  {if $fields.transitioned_c.value == "1"}{assign var="TRANSITIONED_C_CHECKED" value="checked"}{else}{assign var="TRANSITIONED_C_CHECKED" value=""}{/if}<input name="transitioned_c" type="hidden" value="0"><input name="transitioned_c" onclick=\'requireGolive(this.checked);\' type="checkbox" class="checkbox" value="1" {$TRANSITIONED_C_CHECKED}>'
    ,
                  
    'label' => 'LBL_TRANSITIONED',
                ), 
    Please vote for my Cloud Connectors session for SugarCon12
    You'll get to learn some pretty powerful stuff for pulling in and displaying data from your other various systems.

    -----------------------------------------------------------------------------------------
    Modules:
    SecuritySuite (Teams)
    Photo Module
    Follow me on Twitter:eggsurplus

    Your Personal Developer

  2. #2
    wsiedler is offline Sugar Community Member
    Join Date
    Oct 2006
    Location
    Hong Kong
    Posts
    81

    Default Re: HOWTO: Conditionally required field - on the fly

    An excellent tip, can't wait to try it myself.
    Thanks for sharing it, Jason!

    Regards,
    Wolf

  3. #3
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: HOWTO: Conditionally required field - on the fly

    Nice . Please also post it on the Wiki so it doesn't get lost!
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  4. #4
    Thawatchai is offline Junior Member
    Join Date
    Dec 2008
    Posts
    4

    Smile Re: HOWTO: Conditionally required field - on the fly

    The way of Conditionally required field and control form.

    if you have skill of javascript then can you open form AddNew/Edit in folder 'YouSugar\cache\modules\Your\Module\EditView.tpl'

    In this file you will met HTML code But please remember when rebuild agent your loss this your code.

    I think you have fun for modify it.
    Last edited by Thawatchai; 2008-12-26 at 03:42 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Howto get Contact PopUp Field
    By Nico.awc in forum Developer Help
    Replies: 5
    Last Post: 2011-09-27, 09:49 PM
  2. HowTo:Add values of custom field?
    By madmat in forum Help
    Replies: 1
    Last Post: 2008-08-05, 02:00 PM
  3. Replies: 7
    Last Post: 2007-07-13, 02:38 PM
  4. Using conditionally required field
    By thibaultullink in forum Help
    Replies: 0
    Last Post: 2007-03-08, 04:05 PM
  5. Howto add new field
    By bogusman in forum General Discussion
    Replies: 7
    Last Post: 2005-01-28, 10:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •