Wednesday, August 25, 2010

Module Builder support for Regex validation in textfield - part 2

This is the second part of a posting. You can find the first part here Module Builder support for Regex validation in textfield - part 1.

The code changes needed to be able to do this are listed below.



1. include/javascript/javascript.php
a. function addField is modified to add validation of regex, if field has regex addToValidateRegex is called to add js validation on page.

// HACK : MB support for regular expression validation in textfields
// If "regex","regexlabel" and "modulename" not empty then pass values to function "addFieldRegex".
  
 $regex = $this->sugarbean->field_name_map[$field]['regex'];
 $regexlabel = $this->sugarbean->field_name_map[$field]['regexlabel'];
 $modulename = $this->sugarbean->module_dir;
 
 if($regex!="") { 
  $this->addToValidateRegex($field, $type='regex',$displayName, $required, $prefix='',$regex,$regexlabel,$modulename);
 }
// HACK : MB support for regular expression validation in textfields


b. New function addToValidateRegex added

// HACK : MB support for regular expression validation in textfields
// Function to handle regular expression validation.
function addToValidateRegex($field, $type='regex',$displayName, $required, $prefix='',$regex='',
       $regexlabel='',$modulename='') {
 $this->script .= "addToValidateRegex('".$this->formname."', '".$prefix.$field."', '".$type . 
     "', $required,'".$this->stripEndColon(translate($displayName,
     $this->sugarbean->module_dir)) . "','".$regex . "','".
     $regexlabel . "','".$modulename . "');\n";
}
// HACK : MB support for regular expression validation in textfields



2. include/javascript/sugar_grp1.js
a. 4 new variables added in the beginning of the file.

// HACK : MB support for regular expression validation in textfields
var regexlabelIndex = 5;
var modulenameIndex = 6;
var regexIndex = 4;
var regex;
var regexlabel;
var modulename;
// HACK : MB support for regular expression validation in textfields


b. function validate_form modified to support regex validation

function validate_form(formname, startsWith) {
...
    if (!bail) {
     switch (validate[formname][i][typeIndex]) {
     // HACK : MB support for regular expression validation in textfields
     case 'regex':
      var fieldvalue = form[validate[formname][i][nameIndex]].value;
      if (typeof(fieldvalue) != 'undefined' && fieldvalue != "") {
       var regex = validate[formname][i][regexIndex];
       if (typeof(regex) != 'undefined' && regex != "" && regex != null) {
        var regexlabel = validate[formname][i][regexlabelIndex];
        var modulename = validate[formname][i][modulenameIndex];
        regularExpressionTxt = SUGAR.language.get(modulename, regexlabel);
        var re = new RegExp(regex);
        if (!fieldvalue.match(re)) {
         add_error_style(formname, validate[formname][i][nameIndex], regularExpressionTxt + ' ' + validate[formname][i][msgIndex] + ' ' + validate[formname][i][nameIndex]);
         isError = true;
        }
       }
      }
      break;
     // HACK : MB support for regular expression validation in textfields
     case 'email':
      if (!isValidEmail(trim(form[validate[formname][i][nameIndex]].value))) {
       isError = true;
       add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
      }
      break;


c. New function addToValidateRegex added.

// HACK : MB support for regular expression validation in textfields
// Function to perform regular expression validation
function addToValidateRegex(formname, name, type, required, msg, regex, regexlabel, modulename) {
 addToValidate(formname, name, type, required, msg);
 validate[formname][validate[formname].length - 1][regexIndex] = regex;
 validate[formname][validate[formname].length - 1][regexlabelIndex] = regexlabel;
 validate[formname][validate[formname].length - 1][modulenameIndex] = modulename;
}
// HACK : MB support for regular expression validation in textfields



3. modules/DynamicFields/DynamicField.php
a. function addFieldObject modified to save regex, regexmessage & regexlabel

// HACK : MB support for regular expression validation in textfields
$fmd->regex = $field->regex;
$fmd->regexmessage = $field->regexmessage;
$fmd->regexlabel = $field->regexlabel;
// HACK : MB support for regular expression validation in textfields


b. 3 new parameter added to function addField

function addField($name,$label='', $type='Text',$max_size='255', $regex='',$regexmessage='', $regexlabel,$required_option='optional', $default_value='', $ext1='', $ext2='', $ext3='',$audited=0, $mass_update = 0 , $ext4='', $help='',$duplicate_merge=0, $comment=''){
  require_once('modules/DynamicFields/templates/Fields/TemplateField.php');
     $field = new TemplateField();
     $field->label = $label;
        if(empty($field->label)){
            $field->label = $name;
        }
        $field->name = $name;
  $field->type = $type;
  $field->len = $max_size;
  $field->required = (!empty($required_option) && $required_option != 'optional');
  $field->default = $default_value;
  $field->ext1 = $ext1;
  $field->ext2 = $ext2;
  $field->ext3 = $ext3;
  $field->ext4 = $ext4;
  $field->help = $help;

  // HACK : MB support for regular expression validation in textfields
  $field->regex = $regex;
  $field->regexmessage = $regexmessage;
  $field->regexlabel = $regexlabel;
  // HACK : MB support for regular expression validation in textfields

  $field->comments = $comment;
  $field->massupdate = $mass_update;
  $field->duplicate_merge = $duplicate_merge;
  $field->audited = $audited;
  $field->reportable = 1;
        return $this->addFieldObject($field);
    }



4. modules/DynamicFields/templates/Fields/Forms/varchar.tpl
a. Template file is modified to add 2 property of regex validation


{*  HACK : MB support for regular expression validation in textfields *}

 {$MOD.COLUMN_TITLE_REGEX}:{if $hideLevel < 5 }
 {else}

{$vardef.regex}{/if} 








 {$MOD.COLUMN_TITLE_REGEXMESSAGE}:{if $hideLevel < 5 }
 {else}

{$vardef.regex}{/if}




 {$MOD.COLUMN_TITLE_REGEXLABEL}:{if $hideLevel < 5 }
 {else}

{$vardef.regexlabel}{/if}



{*  HACK : MB support for regular expression validation in textfields *}


5. modules/DynamicFields/templates/Fields/TemplateField.php
a. 3 new properties added to class TemplateField


// HACK : MB support for regular expression validation in textfields
var $regex = '';
var $regexmessage = '';
var $regexlabel = '';
// HACK : MB support for regular expression validation in textfields


b. In class variable $vardef_map 3 new property added


var $vardef_map = array(
 'name'=>'name',
 'label'=>'vname',
 // bug 15801 - need to ALWAYS keep default and default_value consistent as some methods/classes use one, some use another...
 'default_value'=>'default',
 'default'=>'default_value',
//  'default_value'=>'default_value',
//  'default'=>'default_value',
 'len'=>'len',
 'required'=>'required',
 'type'=>'type',
 'audited'=>'audited',
 'massupdate'=>'massupdate',
 'options'=>'ext1',
 'help'=>'help',

 // HACK : MB support for regular expression validation in textfields
 'regex'=>'regex',
 'regexmessage'=>'regexmessage',
 'regexlabel'=>'regexlabel',
 // HACK : MB support for regular expression validation in textfields

 'comments'=>'comment',
 'importable'=>'importable',
 'duplicate_merge'=>'duplicate_merge',
 //'duplicate_merge_dom_value'=>'duplicate_merge', //bug #14897
 'reportable' => 'reportable',
 'min'=>'ext1',
 'max'=>'ext2',
 'ext2'=>'ext2',
 'ext4'=>'ext4',
 //'disable_num_format'=>'ext3',
 'ext3'=>'ext3',
 'label_value'=>'label_value',
);


c. function get_db_delete_alter_table modified to generate drop sql statement, value to 3 new property added to call.


function get_db_delete_alter_table($table)
    {
        return $GLOBALS['db']->getHelper()->dropColumnSQL(
            $table,
            array(
                'name' => $this->name,
                'type' => $this->type,
                'size' => $this->size,
    // HACK : MB support for regular expression validation in textfields
       'regex' => $this->regex,
    'regexmessage' => $this->regexmessage,
    'regexlabel' => $this->regexlabel,
       // HACK : MB support for regular expression validation in textfields
    'len'  => $this->len,
                )
            );
    }


d. function get_field_def will return 3 new properties along with other field property.


function get_field_def(){
 $array =  array(
  'required'=>$this->required,
  'source'=>'custom_fields',
  'name'=>$this->name,
  'vname'=>$this->vname,
  'type'=>$this->type,
  'massupdate'=>$this->massupdate,
  'default'=>$this->default,
  'comments'=> (isset($this->comments)) ? $this->comments : '',
  'help'=> (isset($this->help)) ?  $this->help : '',

  // HACK : MB support for regular expression validation in textfields
  'regex'=>$this->regex,
  'regexmessage'=>$this->regexmessage,
  'regexlabel'=>$this->regexlabel,
  // HACK : MB support for regular expression validation in textfields

  'importable'=>$this->importable,
  'duplicate_merge'=>$this->duplicate_merge,
  'duplicate_merge_dom_value'=>$this->duplicate_merge, //nsingh: bug #14897 The UI did not get updated according to $app_list_strings['custom_fields_merge_dup_dom'], so include an extra field for the dom and leave the original duplicate_merge logic intact.
  'audited'=>($this->audited ? 1 : 0),
  'reportable'=>($this->reportable ? 1 : 0),
  );
  if(!empty($this->len)){
   $array['len'] = $this->len;
  }
  $this->get_dup_merge_def($array);
  return $array;
}


e. 3 new property added to function populateFromRow’s array on first line $fmd_to_dyn_map.


$fmd_to_dyn_map = array(
 'comments' => 'comment', 
 'require_option' => 'required', 
 'label' => 'vname',
 'mass_update' => 'massupdate', 
 'max_size' => 'len', 
 'default_value' => 'default',

 // HACK : MB support for regular expression validation in textfields
 'regex' => 'regex',
 'regexmessage' => 'regexmessage',
 'regexlabel' => 'regexlabel'
 // HACK : MB support for regular expression validation in textfields
);



6. modules/EditCustomFields/EditCustomFields.php
a. 3 new parameter added to function add_custom_field, also new parameter values are stored in $fields_meta_data.


function add_custom_field($name, $label, $data_type, $max_size, $regex,$regexmessage,$regexlabel,
 $required_option, $default_value, $deleted, $ext1, $ext2, $ext3, $audited, $mass_update=0, $duplicate_merge=0, $reportable = true)
{
 $module_name = $this->module_name;

 $fields_meta_data = new FieldsMetaData();
 $fields_meta_data->name = $name;
 $fields_meta_data->label = $label;
 $fields_meta_data->module = $module_name;
 $fields_meta_data->data_type = $data_type;
 $fields_meta_data->max_size = $max_size;

 // HACK : MB support for regular expression validation in textfields
 $fields_meta_data->regex = $regex;
 $fields_meta_data->regexmessage = $regexmessage;
 $fields_meta_data->regexlabel = $regexlabel;
 // HACK : MB support for regular expression validation in textfields

 $fields_meta_data->required_option = $required_option;
 $fields_meta_data->default_value = $default_value;
 $fields_meta_data->deleted = $deleted;
 $fields_meta_data->ext1 = $ext1;
 $fields_meta_data->ext2 = $ext2;
 $fields_meta_data->ext3 = $ext3;
 $fields_meta_data->audited = $audited;
 $fields_meta_data->duplicate_merge = $duplicate_merge;
 $fields_meta_data->mass_update = $mass_update;
 $fields_meta_date->reportable = $reportable;  
 $fields_meta_data->insert();

 $custom_table_name = $this->_get_custom_tbl_name();
 $custom_table_exists =
  CustomFieldsTableSchema::custom_table_exists($custom_table_name);

 $custom_fields_table_schema =
  new CustomFieldsTableSchema($custom_table_name);

 if(!$custom_table_exists)
 {
  $custom_fields_table_schema->create_table();
 }

 $result = $custom_fields_table_schema->add_column($name, $data_type,
  $required_option, $default_value);

 return $result;
}


b. 3 new parameter added to function get_custom_field, also new parameter values are retrieved from $fields_meta_data.


function get_custom_field($id, &$name, &$label, &$data_type, &$max_size, &$regex,&$regexmessage,&$regexlabel,
  &$required_option, &$default_value, &$deleted, &$ext1, &$ext2, &$ext3, &$audited,&$duplicate_merge,&$reportable)
{
 $fields_meta_data = new FieldsMetaData($id);
 $name = $fields_meta_data->name;
 $label = $fields_meta_data->label;
 $data_type = $fields_meta_data->data_type;
 $max_size = $fields_meta_data->max_size;

 // HACK : MB support for regular expression validation in textfields
 $regex = $fields_meta_data->regex;
 $regexmessage = $fields_meta_data->regexmessage;
 $regexlabel = $fields_meta_data->regexlabel;
 // HACK : MB support for regular expression validation in textfields

 $required_option = $fields_meta_data->required_option;
 $default_value = $fields_meta_data->default_value;
 $deleted = $fields_meta_data->deleted;
 $ext1 = $fields_meta_data->ext1;
 $ext2 = $fields_meta_data->ext2;
 $ext3 = $fields_meta_data->ext3;
 $audited = $fields_meta_data->audited;  
 $duplicate_merge=$fields_meta_data->duplicate_merge;
 $reportable = $fields_meta_data->reportable;
}


c. 3 new parameter added to function edit_custom_field, also new parameter values are stored in $fields_meta_data.


function edit_custom_field($id, $name, $label, $data_type, $max_size, $regex,$regexmessage,$regexlabel,
 $required_option, $default_value, $deleted, $ext1, $ext2, $ext3, $audited,$duplicate_merge,$reportable)
{
 $module_name = $this->module_name;

 // update the meta data
 $fields_meta_data = new FieldsMetaData();
 $fields_meta_data->id = $id;
 $fields_meta_data->name = $name;
 $fields_meta_data->label = $label;
 $fields_meta_data->module = $module_name;
 $fields_meta_data->data_type = $data_type;
 $fields_meta_data->max_size = $max_size;

 // HACK : MB support for regular expression validation in textfields
 $fields_meta_data->regex = $regex;  
 $fields_meta_data->regexmessage = $regexmessage;    
 $fields_meta_data->regexlabel = $regexlabel; 
 // HACK : MB support for regular expression validation in textfields

 $fields_meta_data->required_option = $required_option;
 $fields_meta_data->default_value = $default_value;
 $fields_meta_data->deleted = $deleted;
 $fields_meta_data->ext1 = $ext1;
 $fields_meta_data->ext2 = $ext2;
 $fields_meta_data->ext3 = $ext3;
 $fields_meta_data->audited=$audited;
 $fields_meta_data->duplicate_merge=$duplicate_merge;   
 $fields_meta_data->reportable = $reportable;     
 $fields_meta_data->update();

 // update the schema of the custom table
 $custom_table_name = $this->_get_custom_tbl_name();
 $custom_fields_table_schema =
  new CustomFieldsTableSchema($custom_table_name);

 $custom_fields_table_schema->modify_column($name, $data_type,
  $required_option, $default_value);
}



7. modules/EditCustomFields/EditView.html
a. 3 new property added to template


{MOD.COLUMN_TITLE_REGEX}:
{MOD.COLUMN_TITLE_REGEXMESSAGE}:
{MOD.COLUMN_TITLE_REGEXLABEL}:




8. modules/EditCustomFields/EditView.php
a. Regex properties assigned to template


// HACK : MB support for regular expression validation in textfields
$xtpl->assign('regex', $focus->regex); 
$xtpl->assign('regexmessage', $focus->regexmessage); 
$xtpl->assign('regexlabel', $focus->regexlabel);
// HACK : MB support for regular expression validation in textfields



9. modules/EditCustomFields/Forms.html
a. 3 new property added to template


{mod.COLUMN_TITLE_REGEX}

{mod.COLUMN_TITLE_REGEXMESSAGE}

{mod.COLUMN_TITLE_REGEXLABEL}





10. modules/EditCustomFields/language/en_us.lang.php
a. Labels at end of file.


// HACK : MB support for regular expression validation in textfields
$mod_strings = array_merge($mod_strings,
 array(
   'COLUMN_TITLE_REGEX' => "Regex Expression",
   'COLUMN_TITLE_REGEXMESSAGE' => "Regex Message",
   'COLUMN_TITLE_REGEXLABEL' => "Regex Label",
 )
);
// HACK : MB support for regular expression validation in textfields



11. modules/EditCustomFields/ListView.html
a. 3 new property added to template


{MOD.COLUMN_TITLE_REGEX}{arrow_start}{regex_arrow}{arrow_end} 
{MOD.COLUMN_TITLE_REGEXMESSAGE}{arrow_start}{regexmessage_arrow}{arrow_end} 
{MOD.COLUMN_TITLE_REGEXLABEL}{arrow_start}{regexlabel_arrow}{arrow_end} 




12. modules/EditCustomFields/Popup.html
a. 3 new property added to template


{mod.COLUMN_TITLE_REGEX}



{mod.COLUMN_TITLE_REGEXMESSAGE}



{mod.COLUMN_TITLE_REGEXLABEL}






13. modules/EditCustomFields/Save.php
a. 3 regex property value from request


// HACK : MB support for regular expression validation in textfields
if(isset($_REQUEST['regex'])){  
 $regex = $_REQUEST['regex'];
}
if(isset($_REQUEST['regexmessage'])){  
 $regexmessage = $_REQUEST['regexmessage'];
}
if(isset($_REQUEST['regexlabel'])){  
 $regexlabel = $_REQUEST['regexlabel'];
}
// HACK : MB support for regular expression validation in textfields

b. $custom_fields->updateField call has added 3 new regex argument
$custom_fields->updateField($id, array('max_size'=>$max_size, 'regex'=>$regex, 'regexmessage'=>$regexmessage,'regexlabel'=>$regexlabel, 'required_option'=>$required_opt, 'default_value'=>$default_value, 'audited'=>$audit_value, 'mass_update'=>$mass_update,'duplicate_merge'=>$_REQUEST['duplicate_merge']));



14. modules/EditCustomFields/Saveold.php
a. Code added to set value of 3 regex variable from $fields_meta_data


// HACK : MB support for regular expression validation in textfields
$regex = $fields_meta_data->regex;
$regexmessage = $fields_meta_data->regexmessage;
$regexlabel = $fields_meta_data->regexlabel;
// HACK : MB support for regular expression validation in textfields



15. modules/EditCustomFields/vardefs.php
a. 3 regex fields added to fields array


'fields' => array (
 'id'=>array('name' =>'id', 'type' =>'varchar', 'len'=>'255', 'reportable'=>false),
 'name'=>array('name' =>'name', 'vname'=>'COLUMN_TITLE_NAME', 'type' =>'varchar', 'len'=>'255'),
 'vname'=>array('name' =>'vname' ,'type' =>'varchar','vname'=>'COLUMN_TITLE_LABEL',  'len'=>'255'),
 'comments'=>array('name' =>'comments' ,'type' =>'varchar','vname'=>'COLUMN_TITLE_LABEL',  'len'=>'255'),
 'help'=>array('name' =>'help' ,'type' =>'varchar','vname'=>'COLUMN_TITLE_LABEL',  'len'=>'255'),
 'custom_module'=>array('name' =>'custom_module',  'type' =>'varchar', 'len'=>'255', ),
 'type'=>array('name' =>'type', 'vname'=>'COLUMN_TITLE_DATA_TYPE',  'type' =>'varchar', 'len'=>'255'),
 'len'=>array('name' =>'len','vname'=>'COLUMN_TITLE_MAX_SIZE', 'type' =>'int', 'len'=>'11', 'required'=>false, 'validation' => array('type' => 'range', 'min' => 1, 'max' => 255),),

 // HACK : MB support for regular expression validation in textfields
 'regex'=>array('name' =>'regex' ,'type' =>'varchar','vname'=>'COLUMN_TITLE_REGEX',  'len'=>'255'),
 'regexmessage'=>array('name' =>'regexmessage' ,'type' =>'varchar','vname'=>'COLUMN_TITLE_REGEXMESSAGE',  'len'=>'255'),
 'regexlabel'=>array('name' =>'regexlabel' ,'type' =>'varchar','vname'=>'COLUMN_TITLE_REGEXLABEL',  'len'=>'255'),
  // HACK : MB support for regular expression validation in textfields

 'required'=>array('name' =>'required', 'type' =>'bool', 'default'=>'0'),
 'default_value'=>array('name' =>'default_value', 'type' =>'varchar', 'len'=>'255', ),
 'date_modified'=>array('name' =>'date_modified', 'type' =>'datetime', 'len'=>'255',),  
 'deleted'=>array('name' =>'deleted', 'type' =>'bool', 'default'=>'0', 'reportable'=>false),
 'audited'=>array('name' =>'audited', 'type' =>'bool', 'default'=>'0'),  
 'massupdate'=>array('name' =>'massupdate', 'type' =>'bool', 'default'=>'0'), 
 'duplicate_merge'=>array('name' =>'duplicate_merge', 'type' =>'short', 'default'=>'0'),  
 'reportable' => array('name'=>'reportable', 'type'=>'bool', 'default'=>'1'),
 'importable' => array('name'=>'importable', 'type'=>'varchar', 'len'=>'255'),
 'ext1'=>array('name' =>'ext1', 'type' =>'varchar', 'len'=>'255', 'default'=>''),
 'ext2'=>array('name' =>'ext2', 'type' =>'varchar', 'len'=>'255', 'default'=>''),
 'ext3'=>array('name' =>'ext3', 'type' =>'varchar', 'len'=>'255', 'default'=>''),
 'ext4'=>array('name' =>'ext4', 'type' =>'text'),
),



16. modules/ModuleBuilder/controller.php
a. function action_SaveLabel modified to set regex validation message in request


function action_SaveLabel ()
{
 if (! empty ( $_REQUEST [ 'view_module' ] ) && !empty($_REQUEST [ 'labelValue' ]))
 {
  $_REQUEST [ "label_" . $_REQUEST [ 'label' ] ] = $_REQUEST [ 'labelValue' ] ;
 
  // HACK : MB support for regular expression validation in textfields
  // To add  'regexlabel' and 'regexmessage' option in language file.
  if($_REQUEST [ 'regexlabel' ]!="") {
   $_REQUEST [ "label_" . $_REQUEST [ 'regexlabel' ] ] = $_REQUEST [ 'regexmessage' ] ;
  } 
   // HACK : MB support for regular expression validation in textfields
 
  require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
  $parser = new ParserLabel ( $_REQUEST['view_module'] , isset ( $_REQUEST [ 'view_package' ] ) ? $_REQUEST [ 'view_package' ] : null ) ;
  $parser->handleSave ( $_REQUEST, $GLOBALS [ 'current_language' ] ) ;

 }
 $this->view = 'modulefields' ;
}


b. function action_SaveField modified to save regex validation message, before saving module


// HACK : MB support for regular expression validation in textfields
// To add  'regexlabel' and 'regexmessage' option in language file
if($_REQUEST [ 'regexlabel' ]!="") {
 $module->setLabel ( $GLOBALS [ 'current_language' ], $_REQUEST [ 'regexlabel' ], $_REQUEST [ 'regexmessage' ] ) ;
}
// HACK : MB support for regular expression validation in textfields



17. modules/ModuleBuilder/MB/MBField.php
a. 3 new call member variable added to class MBField


// HACK : MB support for regular expression validation in textfields
//To add options "regex","regexmessage" and "regexlabel" in variable defination. 
var $regex = false;
var $regexmessage = false;
var $regexlabel = false;
// HACK : MB support for regular expression validation in textfields


b. In function getFieldVardef, regex, regexmessage & regexlabel set in $vardef array.


// HACK : MB support for regular expression validation in textfields
// To add options "regex","regexmessage" and "regexlabel" in variable defination
 if(!empty($this->regex))$vardef['regex'] = $this->regex;
 if(!empty($this->regexmessage))$vardef['regexmessage'] = $this->regexmessage;
 if(empty($this->regexlabel))$this->regexlabel = 'LBL_'.strtoupper($this->regex);
// HACK : MB support for regular expression validation in textfields



18. modules/ModuleBuilder/MB/MBVardefs.php
a. Function save is modified to unset regex message value, because it will not be save in vardefs, it will be saved in lang file.


function save(){
 $header = file_get_contents('modules/ModuleBuilder/MB/header.php');
  // HACK : MB support for regular expression validation in textfields
 // To remove 'regexmessage' option from variable defination
 foreach($this->vardef['fields'] as $key=>$value)
 {  
  unset($this->vardef['fields'][$key]['regexmessage']);
 }
  // HACK : MB support for regular expression validation in textfields
 write_array_to_file('vardefs', $this->vardef, $this->path . '/vardefs.php','w', $header);
}



19. modules/ModuleBuilder/views/view.labels.php
a. In function display() each field is filtered


// HACK : MB support for regular expression validation in textfields
// To show options "regex","regexmessage" and "regexlabel" in label defination  
$formatted_mod_strings[$name] = htmlentities($label, ENT_QUOTES, 'UTF-8');
// HACK : MB support for regular expression validation in textfields



20. modules/ModuleBuilder/views/view.modulefield.php
a. In function fetch(), regex label is retrevied from lang file & set in $vardefs.


// HACK : MB support for regular expression validation in textfields
// To get regexlabel=>regexmessage value from language file by .
// This is for studio. 
if(isset($vardef['regexlabel'])){
 $language_value='';
 if(!empty($vardef['regexlabel'])){
  $language_value=translate($vardef['regexlabel'], $moduleName);
  if(!empty($language_value))
  $vardef['regexmessage']=$vardef['regexlabel'];
  $vardef['regexmessage']=$language_value;
 }
}   
// HACK : MB support for regular expression validation in textfields



21. Following files are help file for regex. Question mark icon shown in regex field inmodule builder while editing field. Clicking on question mark icon will show help from following file.
a. modules/DynamicFields/language/en_us.regex.index.html
b. modules/DynamicFields/language/regex
c. modules/DynamicFields/language/regex/step1.jpg
d. modules/DynamicFields/language/regex/step2.JPG
e. modules/DynamicFields/language/regex/step3.JPG
f. modules/DynamicFields/language/regex/step4.JPG




22. After applying patch run following SQL, this will create columns for regex metadata in fields_meta_data table.


ALTER TABLE fields_meta_data ADD COLUMN size VARCHAR (255) NULL,
  ADD COLUMN regex VARCHAR (255) NULL,
  ADD COLUMN regexmessage VARCHAR (255) NULL,
  ADD COLUMN regexlabel VARCHAR (255) NULL


The patch file and the modified SugarCrm files can be downloaded here 2010-08-25-RegexFieldValidation.zip

These files are used at your own risk ... (the normal disclaimer goes here)
Post a Comment