I explained a bit here, but due to this now being a specific hurtle I wonder inf anyone could help me understand how inline edits are implemented.
https://suitecrm.com/forum/developer-help/7453-creating-custom-field-types
I have a custom field type, and I have my own php being ran before a save. That code does not get ran for inline editing as the process is different with inline editing saves.
Anyone have a clue how I can include custom code t the save process for inline editing for custom field types?
Thanks.
custom/include/SugarFields/Fields/SocialSecurity/SugarFieldSocialSecurity.php
<?php
/*********************************************************************************
Custom SugarField that validates and compartmentalizes Social Security Numbers.
User will have to enter social from javascript validation and php validation of XXX-XX-XXXX
If user is in role SSNBLOCK only the last 4 of the social will be displayed EX: ***-**-6789
So if the user hits save, this save logic will ensure the field is not saved as ***-**-6789
but rather keep the original data of 123-45-6789
If the field has an updated Social Security Number then it will save.
EX: Original SS = 123-45-6789 and has a new value of ***-**-6789 it will not be saved.
Original SS = 123-45-6789 and has a new value of 987-65-4321 it WILL be saved and updated.
This is to allow only the correct users to view the full SS and any user to update the field.
Great! and its a field type, so this type of code may be used now for CC validation or postal code validation.
********************************************************************************/
require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
require_once('data/SugarBean.php');
class SugarFieldSocialSecurity extends SugarFieldBase {
//need to specify to system to use SearchView.tpl for search instead of the edit view field with masking
function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
return $this->getSmartyView($parentFieldArray, $vardef, $displayParams, $tabindex, 'SearchView');
}
//here we alter the save logic to check for ***-**- masking and prevent the system form saving this,
//also do secondary validaiton to prevent save incase javascript fails to work on the webpage.
public function save($bean, $params, $field, $properties, $prefix = '') {
if ( isset($params[$prefix.$field]) ) {
if(isset($properties['len']) && isset($properties['type']) && $this->isTrimmable($properties['type'])){
$bean->$field = trim($this->unformatField($params[$prefix.$field], $properties));
}
else {
$bean->$field = $this->unformatField($params[$prefix.$field], $properties);
}
}
$bean_field_data = $bean->$field;
//Here we do php validation, so if the number contains * from masking, or is incorrect format and js
//failed to load and validate then we prevent the save by using the previous db value
if (!preg_match("/^(?!\b(\d)\1+-(\d)\1+-(\d)\1+\b)(?!123-45-6789|219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4}$/", $bean_field_data)){
$bean->$field = $bean->fetched_row[$field];
}
}
}
?>