Add validation to custom field in Campaigns module

Hi,
    We're using Sugar version 7.2. We have a requirement to add a time field in the Campaigns module. For this I created a custom field using Studio called start time. Now since this was a free text field I had to add validations so only valid times were entered. I first made my changes in the Wizard by customising the WizardCampaignHeader.tpl in custom/modules/Campaigns/tpls/WizardCampaignHeader.tpl. I added my field
<tr>        <td scope="col"><span sugar='slot14'>{$MOD.LBL_START_TIME}:</span sugar='slot'></td>        <td><span sugar='slot14b'><input id='start_time' name='wiz_step1_start_time_c' title='{$MOD.LBL_START_TIME}' type="text" value="{$START_TIME_C}" ></span sugar='slot'></td>        </tr>

And after that added validation for my field

addToValidate('wizform', 'start_time', 'time', false,  document.getElementById('start_time').title);

So now it works okay. Although I haven't figured out how to add validations when I click on the edit button and then click on save. Can someone please provide some guidance?

Kind Regards,
Madhav Shenoy
  • Thanks for the suggestion.Tried that. Doesn't work. Not sure if I'm doing something wrong here. I created a create-actions.js and record.js in the folders mentioned
    Create-actions extendsFrom: 'CreateActionsView'  and record.js extendsFrom: 'CampaignsRecordView' which I'm not sure exists.

    And this is the validationscript


    _doValidateTime: function(fields, errors, callback) {        //validate type requirements        if (!_.isEmpty(this.model.get('start_time_c')))        {            var isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])?$/.test(this.model.get('start_time_c'));            if(!isValid)            {                errors['start_time_c'] = errors['start_time_c'] || {};                            }                    }        callback(null, fields, errors);    },
  • Ok I finally managed to do it. Not sure if this is upgrade safe though. There was already an existing file custom/modules/Campaigns/metadata/editviewdefs.php. It had an entry for javascript

    $viewdefs['Campaigns'] =
    array (
      'EditView' =>
      array (
        'templateMeta' =>
        array (
          'maxColumns' => '2',
          'widths' =>
          array (
            0 =>
            array (
              'label' => '10',
              'field' => '30',
            ),
            1 =>
            array (
              'label' => '10',
              'field' => '30',
            ),
          ),
          'javascript' => '<script type="text/javascript" src="include/javascript/popup_parent_helper.js?v=lfl10z_8P5kB8KpsuPdZxg"></script>

    I just added the following line
      <script type="text/javascript" src="custom/modules/Campaigns/include/javascript/Validate.js"></script>
    And put my validation in the script file. Works like a charm.
  • You have right. Campaigns is a #bwc modul, works with editviewdefs.php (in iframe ) and not with record.php :)