Make form readonly conditionally

can i turn lead’s form to be readonly if status of lead is changed to be closed or converted

Lead Conversion Option
This might help

it only gives two options to move or copy none are to disable lead

Disable convert lead action for converted leads

Are you able to work with hooks? you could e.g. remove a security group from a lead as soon as it is “closed”/converted. Assuming that the security group grants the edit right, the lead would be read-only after removing the group.

can you please give a code example

sure, you can find examples in the documentation: Logic Hooks :: SuiteCRM Documentation

If I were you, I would try to start with an after-save-hook for leads. in that hook, you unset the relationship to the security group that is related to the lead. so if this is your approach, you need to setup the security group/permissions first (otherwise your hook might work and remove the securitygroup, but the contact remains editable).

 0 => 
          array (
            'name' => 'last_name',
            'label' => 'LBL_LAST_NAME',
            'customCode' => '<input type="text" tabindex="0"  value="{$fields.last_name.value}" maxlength="99" size="30" id="last_name" name="last_name" {$readOnly}>',
          ),

in detailviewdefs

 class LeadsViewDetail extends ViewDetail{
public function __construct()
{
    parent::__construct();
    $this->useForSubpanel = true;
    $this->useModuleQuickCreateTemplate = true;
}
public function display()
{
    global $current_user;

    if( $this->bean->status=='Closed'){
        $isClosed=false;
    }
    // Set the $readOnly variable based on the user's administrator status
    $readOnly = $isClosed ? '' : 'readonly = "readonly"';

    // Assign $readOnly to Smarty template
    $this->ev->ss->assign('readOnly', $readOnly);
    

    parent::display(); // Call the parent display function to render the view
}
}

in detail.view.php
can’t i use this method

Is it working? Did you create test lead and try it?

No it is not
Last name field is always read only now I don’t understand why

You added customCode for last_name to be readonly field

What about this logic hook code?

class LeadReadOnlyHook
{
    public function before_save($bean, $event, $arguments)
    {
        if ($bean->status === 'Closed' || $bean->status === 'Converted') {
            $bean->is_readonly = true;
        } else {
            $bean->is_readonly = false;
        }
    }
}

I thought it was conditional

I didn’t think this was an option thank you will try it

Do you think this is better one?

$readOnly = $isClosed ? 'readonly="readonly"' : ' ';

i tried this but it didn’t work