Results 1 to 5 of 5

Thread: Hide or show panel in Accounts if checkbox is checked

  1. #1
    ldbtractor is offline Member
    Join Date
    Sep 2008
    Posts
    7

    Default Hide or show panel in Accounts if checkbox is checked

    G'day

    I have used SugarCRM but am new to customizing it. I am using the latest SugarCRM 5.1 package on CentOS 5.1.

    I have followed the "Programmatically Hiding and Displaying Panels Based on the Value of a Drop Down" with the adjustment that I've set it to use the checkbox value. I have the Developer's Guide, User Guide, Admin Guide and several postings/examples. I am still at a loss.

    The following code will hide or display the panel I want, if I set the value manually in testing. But I can't find where to tell Sugar about the onchange. Is it automatically picking it up from somewhere? Is there just a javascript error that I'm not seeing, my javascript is rather rusty, trying to fix that..

    The code is in "modules/Accounts/views/view.edit.php:. If I uncomment the "document.getElementById("vendor_flag_c").onchange " line and the corresponding "}" it displays the panel regardless of the value. That is why it is currently commented out.

    PHP Code:
    <?php 
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once(
    'include/MVC/View/views/view.edit.php');
    class 
    AccountsViewEdit extends ViewEdit {
           function 
    AccountsViewEdit(){
                
    parent::ViewEdit();
           }
           function 
    display() {


    $js=<<<EOQ
             
            <script>

                //document.getElementById("vendor_flag_c").onchange = function() {
                    var vendor_flag = document.getElementById("vendor_flag_c");   
                    var vendor_panel= document.getElementById("LBL_PANEL2");
                    
                if(vendor_flag = 1) 
                {
                    vendor_panel.style.visibility = "hidden";
                } else {
                    vendor_panel.style.visibility = "visible";  
                }
                vendor_panel.innerHTML;

               //};

            $prePop;
            </script>
    EOQ;
                           
    parent::display();
                           echo 
    $js;

                     }
    }
    ?>

    Glad to read a document I missed. But I've read such a sea of them, I think I'm somewhat lost in all the info at this point. Any suggestions, docs etc are greatly appreciated.

    Thank you.
    Last edited by ldbtractor; 2008-09-22 at 12:52 AM. Reason: Additional information

  2. #2
    ldbtractor is offline Member
    Join Date
    Sep 2008
    Posts
    7

    Default Re: Hide or show panel in Accounts if checkbox is checked

    G'day

    Since I had made alot of changes and somewhat wandered from the original "howto" that I mentioned, I went back and tried again. I have a copy closer to what is in the original and now understand alot more about it , using some of the stuff I'd read in the meantime.

    This code will read the checkbox and hide or display the panel just fine upon load. But I am having a hard time understanding how this code actually gets recognized by SugarCRM using AJAX. I've read about 'customCode" and 'displayParams' and am still seeing what I can find on that subject. But the how-to does not mention putting the code in a separate js and that appears to be what I need to do according to what I have read. I am sure that this is the missing piece. Can someone please clarify or point me to a doc that does, re; how to tell SugarCRM to do this every time the checkbox changes?

    The alerts were just to show me I was getting the right checkbox value.
    The "onchange" line below is commented out because it stops the code from working. Possibly a syntax error there is my problem?

    PHP Code:
    <?php 
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once(
    'include/MVC/View/views/view.edit.php');
    class 
    AccountsViewEdit extends ViewEdit {
           function 
    AccountsViewEdit(){
                
    parent::ViewEdit();
           }
           function 
    display() {

    $js=<<<EOQ
             
            <script>
                        //var value = document.getElementById("vendorflag_c").value;
                    //document.getElementById("vendorflag_c").onchange = function () {

                        if (document.getElementById("vendorflag_c").checked == true) {
                                alert ("true");
                            } else { 
                                alert ("false");
                                document.getElementById("LBL_PANEL1").style.display="none"; 
                            }


            </script>
    EOQ;
                           
    parent::display();
                           echo 
    $js;

                     }
    }
    ?>

  3. #3
    ldbtractor is offline Member
    Join Date
    Sep 2008
    Posts
    7

    Default Re: Hide or show panel in Accounts if checkbox is checked

    G'day

    Just an update on this.

    I've gotten it to work now. I have made a few changes by now but I know which. I have to go back and check what the minimum was to make this work. Take out the stuff I don't think is necessary now. and retest on my clean copy. I'll post once I know in case it's useful.

    ......

  4. #4
    varun.shesh is offline Member
    Join Date
    Mar 2009
    Posts
    5

    Question Re: Hide or show panel in Accounts if checkbox is checked

    Quote Originally Posted by ldbtractor View Post
    G'day

    Just an update on this.

    I've gotten it to work now. I have made a few changes by now but I know which. I have to go back and check what the minimum was to make this work. Take out the stuff I don't think is necessary now. and retest on my clean copy. I'll post once I know in case it's useful.

    ......
    Hi
    This is varun, will you please post the code of hide and show of panel based on checkbox value. it is really important to me. i am waiting for your response
    Thank You,
    Varun.

  5. #5
    dbetancourt is offline Sugar Community Member
    Join Date
    Oct 2010
    Posts
    19

    Default Re: Hide or show panel in Accounts if checkbox is checked

    First, thanks to ldbtractor because the line:

    Code:
    //document.getElementById("vendorflag_c").onchange = function () {
    helped me solve my problem

    Now, here's something that might help you.

    There are two things you have to change:

    1) The location of
    Code:
    parent::display();
    has to be in the beginning of the display() function, not at the end.

    2) You have to scape the quotes (only the double ones). For example, instead of:

    Code:
    document.getElementById("your_field_name").onchange = function
    you should use:

    Code:
    document.getElementById(\"your_field_name\").onchange = function
    Here is a example: (Please don't copy paste right away, first change the words YOUR_CHECKBOX for the name of your checkbox)

    PHP Code:
    public function display() {
            
    parent::display();
            echo 
    "<script>
                document.getElementById(\"YOUR_CHECKBOX\").onchange = function () {
                    if(document.getElementById('YOUR_CHECKBOX').checked){
                        alert('checked');
                    }else{
                        alert('NO - checked');
                    }
                }
            </script>"
    ;

    Remember, if you're going to use quotes scape them.
    Last edited by dbetancourt; 2011-01-05 at 05:14 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 2008-08-14, 09:14 PM
  2. Replies: 0
    Last Post: 2008-07-11, 05:33 PM
  3. Replies: 1
    Last Post: 2007-04-09, 05:11 PM
  4. Creating sub-accounts that don't show under Accounts tab
    By rriedle in forum Feature Requests
    Replies: 0
    Last Post: 2007-04-08, 02:00 AM
  5. Replies: 1
    Last Post: 2006-09-11, 03:38 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
  •