Results 1 to 6 of 6

Thread: Disable field

  1. #1
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Disable field

    I have a field that i want to be disabled on loading the module in sugar 5.2.0h. to test i add this to the opportunities module:

    PHP Code:
    => 
            array (
              
    'label' => '10',
              
    'field' => '30',
            ),
          ),
              
    //this part here
          
    'includes'=> array(  
            array(
    'file'=>'custom/modules/Opportunities/disable.js'),
         ),
             ... 
    and in disable.js

    Code:
    function disable_field()
    {
    getElementsByName('amount')[0].disabled=true;
    } 
    
    if (window.addEventListener)
    window.addEventListener("load", disable_field, false);
    else if (window.attachEvent)
    window.attachEvent("onload", disable_field)
    else
    window.onload=disable_field
    but when I try to create a new record the amount field is still enabled

    i also tried putting in index.php, editviewdefs.php and Opportunityvardefs.php
    PHP Code:
    echo '<input type="hidden" onLoad="getElementsByName(\'amount\')[0].disabled=true">'
    on a side note adding a button with the above code and change to onclick works when you click the button

    PHP Code:
    echo '<button onClick="getElementsByName(\'amount\')[0].disabled=true">Click</button>'
    a simple question is why doesn't this work

    PHP Code:
    array (
                
    'name' => 'sales_stage',
                
    'displayParams' => 
                array (
                  
    'required' => true,
                  
    'javascript' => 'onload="getElementsByName(\'sales_stage\')[0].disabled=true"',
                ),
                
    'label' => 'LBL_SALES_STAGE',
              ), 
    but i change to onclick it works when i click it, so why doesn't the onload function work in 5.2.0h

    can anyone tell me why this isn't working
    Last edited by blitz2190; 2009-08-13 at 03:59 AM.

  2. #2
    salesagility's Avatar
    salesagility is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    2,379

    Default Re: Disable field

    There may be a simpler way to disable a field ...

    goto Admin>Studio>Opportunities ... editview & detailview

    Drag and drop the field you don't want

  3. #3
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Re: Disable field

    because i need the field later. when i figure this out it will be going in a custom module that will only enable the field when a certain user is editing it, which i will be able to do with enhanced studio the only problem is enhanced studio demo only works when editing not creating a record. so my question is when do i put the onload function where it will be called by the module

  4. #4
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Re: Disable field

    also why does this work
    PHP Code:
    array (
                
    'name' => 'sales_stage',
                
    'displayParams' => 
                array (
                  
    'required' => true,
                  
    'javascript' => 'onclick="this.disabled=true;"'
    but this doesn't
    PHP Code:
    array (
                
    'name' => 'sales_stage',
                
    'displayParams' => 
                array (
                  
    'required' => true,
                  
    'javascript' => 'onload="this.disabled=true;"'

  5. #5
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Re: Disable field

    does any one know how to disable fields with javascript

  6. #6
    blitz2190 is offline Senior Member
    Join Date
    Jul 2009
    Posts
    105

    Default Re: Disable field

    i finally figured this out
    in custom/modules/module_name add the javascript in in the $viewdefs

    PHP Code:
    $viewdefs ['module_name'] = 
    array (
      
    'EditView' => 
      array (
        
    'templateMeta' => 
        array (
          
    'form' => 
          array (
            
    'enctype' => 'multipart/form-data',
            
    'headerTpl' => 'modules/moudule_name/tpls/EditViewHeader.tpl',
          ),
          
    'maxColumns' => '2',
          
    'widths' => 
          array (
            
    => 
            array (
              
    'label' => '10',
              
    'field' => '30',
            ),
            
    => 
            array (
              
    'label' => '10',
              
    'field' => '30',
            ),
          ),
          
    //add this code
          
    'javascript' => '<script>
    window.onload=function() 
    {literal} { {/literal}
          document.getElementById(\'field_name\').disabled=true;
    {literal} } {/literal}
      </script>'

    Last edited by blitz2190; 2009-08-17 at 03:18 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. disable a field conditionnally
    By clement in forum Developer Help
    Replies: 19
    Last Post: 2010-06-18, 11:55 PM
  2. Can we disable any field
    By nandynandy in forum Developer Help
    Replies: 11
    Last Post: 2008-05-01, 09:50 PM
  3. Disable field script
    By wica in forum Help
    Replies: 4
    Last Post: 2008-04-13, 06:28 PM
  4. Replies: 0
    Last Post: 2007-04-25, 12:45 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
  •