>7.9 set readonly in javascript

Hi,

we are upgrading SugarCRM from 7.6 to 7.9 and setting readonly depending on values in Javascript does not work anymore. Cause the model is availble after rendering, setting a field to readonly has no effect when it's used in  this.on('render', ... or  this.model.once('sync', ...

We can't use PHP dependencies cause the readonly property should not be used by the API. This is an example code:

handleFieldProperties: function() {
     var type = this.model.get('list_type');         
     _.each(this.meta.panels, function(panel) {
        _.each(panel.fields, function(field, index, list){
            if (_.isString(field)) {
                field = {name: field};
            }
            if (type == 'unique_campaign' && field.name == 'description') {
                field.readonly = true;
                field.required = false;
                list[index] = field;
            }
        });
    }, this);
},

Has someone a solutions do set these fields to readonly and required = false?

Best regards

Harald Kampen##

  • Hi Harald Kampen 

    Why to do that through javascript instead of Dependency ReadOnly?

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi André,

    we have different requirements what's allowed by UI and by API. When I use dependencies, the API call, in this case, cannot change the prospect list to a different type, which is required in some cases.

    Regards

  • Actually you can change it under an API call. You just need to configure a custom flag which would be populated only by the API, in some specific situations, and you have to introduce such flag in the value of ReadOnly Dependency.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • That would be a workaround if not other way could be found. API calls shouldn't change cause different applications are involved.

  • I just remembered it is possible to configure view specific dependencies.

    Take a look at the file modules/WebLogicHooks/clients/base/views/record/record.php.

    This way you can easily setup dependencies which will only affect a specific view on browsing SugarCRM application.

    Kind regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Sounds good for me. When it work, I post the solution.

  • Hi André,

    the dependency action ReadOnly simply sets the fields to read only with some Javascript in the view and has no effect on API calls. We use this, but it's not future save, cause ReadOnly is not defined to be used only in the UI.

    it would be great to have the abilty again to set read-only and  required in Javascripts.

    <?php
    $dependencies['ProspectLists']['UniqueCampaign'] = array(
        'hooks' => array("edit"),
        'trigger' => 'true',
        'triggerFields' => array('list_type'),
        'onload' => true,
        'actions' => array(
            array(
                'name' => 'ReadOnly',
                'params' => array(
                    'target' => 'list_type',
                    'value' => 'equal($list_type,"unique_campaign")',
                ),
            ),
            array(
                'name' => 'ReadOnly',
                'params' => array(
                    'target' => 'name',
                    'value' => 'equal($list_type,"unique_campaign")',
                ),
            ),
            array(
                'name' => 'ReadOnly',
                'params' => array(
                    'target' => 'campaign_group',
                    'value' => 'equal($list_type,"unique_campaign")',
                ),
            ),
            array(
                'name' => 'ReadOnly',
                'params' => array(
                    'target' => 'primary_campaign_group',
                    'value' => 'equal($list_type,"unique_campaign")',
                ),
            ),
        ),
    );

    Regards

    Harald

  • I didn't get the point

    You can easily toggle ReadOnly/SetRequired in the same field under the same dependency.

    André Lopes
    Lampada Global
    Skype: andre.lampada