Results 1 to 3 of 3

Thread: How make a field readonly while editing

  1. #1
    prajeesh is offline Senior Member
    Join Date
    Jun 2009
    Posts
    64

    Default How make a field readonly while editing

    Hi all,

    I would like to how i can make a field readonly while editing a record. But the field should be active while adding the record. Please help me in this,

    Thanks,
    Prajeesh

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: How make a field readonly while editing

    You need to create a custom view for the module (custom/modules/<ModuleName>/views/view.edit.php) containing something like that:
    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once(
    'include/MVC/View/views/view.edit.php');

    class <
    ModuleName>ViewEdit extends ViewEdit {
        function 
    display() {
            require_once(
    'modules/Administration/QuickRepairAndRebuild.php');

            
    $selected_actions = Array('clearTpls');
            
    $modules = Array('<ModuleName>');
            
    $RepairAndClear = new RepairAndClear();
            
    $RepairAndClear->repairAndClearAll($selected_actions$modules$autoexecute true$show_output false);

            if(
    $this->bean->id != '') {
                foreach(
    $this->ev->defs as $defs => $def_detail) {
                    foreach(
    $def_detail as $panel => $panel_defs) {
                        if(
    is_array($panel_defs)){
                            foreach(
    $panel_defs as $row => $row_defs) {
                                foreach(
    $row_defs as $field => $field_defs) {
                                    if(
    is_array($field_defs)) {
                                        if(
    $this->ev->defs[$defs][$panel][$row][$field]['name'] == '<FieldName>') {
                                            
    $this->ev->defs[$defs][$panel][$row][$field]['type'] = 'readonly';
                                        }
                                    } else {
                                        if(
    $field_defs == '<FieldName>') {
                                            
    $this->ev->defs[$defs][$panel][$row][$field] = array(
                                                
    'name' => $field_defs,
                                                
    'type' => 'readonly',
                                            );
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            
    $this->ev->process();

            
    parent::display();
        }
    }
    ?>
    Obviously you need to replace the <ModuleName> and <FieldName> according to the module and field you want to customize.

    Regards
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    bharat12345 is offline Sugar Community Member
    Join Date
    May 2010
    Location
    India
    Posts
    56

    Post Re: How make a field readonly while editing

    Hi,
    I have used the following code for text field.

    $modules = Array('<ModuleName>'); // Module Name - Bank

    if ($this->ev->defs[$defs][$panel][$row][$field]['name'] == '<FieldName>') // Field Name = share_price

    And add the Custome folder/ modulebuilder \packages \ <Module Name> \ view \ view.edit.php

    The text filed is not readonly.

    any other solutions.


    Thanks
    Bharat
    Last edited by bharat12345; 2010-06-18 at 11:48 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to make field readonly
    By zohaib in forum Developer Help
    Replies: 12
    Last Post: 2011-09-26, 10:39 PM
  2. How can i make text box field readonly in a module ?
    By rahulbhandari in forum Developer Help
    Replies: 17
    Last Post: 2010-07-07, 03:31 AM
  3. Make field readonly based on field contents?
    By thettenhausen in forum Developer Help
    Replies: 6
    Last Post: 2009-07-24, 09:57 AM
  4. Override view.edit.php to make fields readonly
    By eggsurplus in forum Developer Help
    Replies: 7
    Last Post: 2008-10-09, 03:44 PM
  5. Replies: 10
    Last Post: 2008-05-07, 12:18 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
  •