How to make Case description readonly after save?

How to make  Cases description readonly in editview after it has been save?

TIA,

Longki Dela Cruz

  • is there a way using logic hooks after save wherein the fields['description'][readonly]=true;?

    or any js to make this possible? readonly in editview?

  • Hello Longki,

        You can js code like this,

      

     $('#description').prop('readonly', true);
    

         Let me know, if it works or not.

  • Hi Sohan Tirpude,

    THanks for the reply. In the _render function sir?

    Regards,

    Longki

  • i solved it using this http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.6/Extension_Framework/Dependencies/

    i created a file /custom/Extension/modules/Cases/Ext/Dependencies/description_readonly.php

    <?php

    $dependencies['Cases']['description_readonly'] =    array(

        'hooks' => array("edit"),

        'trigger' => 'not(equal($description,""))', //check if  the field has a value so that it will trigger

        'triggerFields' => array('description'),

        'onload' => true,

        //Actions is a list of actions to fire when the trigger is true

        'actions' => array(

            array(

                'name' => 'ReadOnly',

                //The parameters passed in will depend on the action type set in cases.description field

                'params' => array(

                    'target' => 'description',

                    'value' => 'true',

                ),

            ),

        ),

    );

    then created a blank file /custom/modules/Cases/Ext/Dependencies/deps.ext.php

    so that after Quick Repair and Rebuild the description_readonly.php will be merged there.

    after QRR you will find in that file the auto-generated merging of codes..

    <?php

    // WARNING: The contents of this file are auto-generated.

    //Merged from custom/Extension/modules/Cases/Ext/Dependencies/description_readonly.php

    $dependencies['Cases']['description_readonly'] =    array(

        'hooks' => array("edit"),

        'trigger' => 'not(equal($description,""))', //check if  the field has a value so that it will trigger

        'triggerFields' => array('description'),

        'onload' => true,

        //Actions is a list of actions to fire when the trigger is true

        'actions' => array(

            array(

                'name' => 'ReadOnly',

                //The parameters passed in will depend on the action type set in cases.description field

                'params' => array(

                    'target' => 'description',

                    'value' => 'true',

                ),

            ),

        ),

    );

    HTH,

    Longki

  • Found the very correct solution emailed by Ajay Kumar to me :-) as for the latter after you hover out to the field it will be automatically set to readonly even if you havent saved it yet. Here's the fix.

    QOUTE from Ajay:

    Hi Longki,

    Good day too!

    1.You can make certain fields readonly by writing dependency.

    2.If you want to make it fields to be readonly only specific views, you can try below.

    Extend "buildGridsFromPanelsMetadata" this method to custom,and push your fields into this.noEditFields variable,this is how sugar is making fields readonly.

    Below is the code snippet,you can copy this code and make changes according to your condition.I tried in recordview.

    Note:we no need to call this method on initialize.

    _buildGridsFromPanelsMetadata:function(panels){

            var noEditFields = new Array();
            this._super('_buildGridsFromPanelsMetadata',[panels]);
            noEditFields.push('phone_alternate');
            this.noEditFields=noEditFields;
        },

    Thanks & Regards

    AjayKumar B

    HTH,

    Longki Dela Cruz

  • Hi Longki,

    You have to make few changes in your dependency code to make it work when it is saved.You have given triggerFields as description,so dependency will get triggered,when we filled value for that.

    But,If you want to make it readonly once it is saved,you have to remove description field from triggerFields.Then it will work properly.

    Here is the modified dependency code.check it out.

    <?php
    $dependencies['Cases']['description_readonly'] =    array(
        'hooks' => array("edit"),
        'trigger' => 'true', //check if  the field has a value so that it will trigger
        'triggerFields' => array( ),
        'onload' => true,
        //Actions is a list of actions to fire when the trigger is true
        'actions' => array(
            array(
                'name' => 'ReadOnly',
                //The parameters passed in will depend on the action type set in cases.description field
                'params' => array(
                    'target' => 'description',
                    'value'=> 'not(equal($description,""))',
                ),
            ),
        ),
    );
    
  • thanks for this Ajay Kumar i guess ill stick with the javascript you gave me.. hmm this would also suffice. thanks for giving all the solution either by php or js. :-)

    Regards,

    Longki