From 1cd2bb67abc5f10f9a9990af0b848582302673c9 Mon Sep 17 00:00:00 2001 From: satish <satish.dvnk@vtiger.com> Date: Fri, 28 Apr 2017 10:52:49 +0530 Subject: [PATCH] Fixes #511 - Percentage field 0.000 default value --- .../v7/modules/Vtiger/uitypes/Percentage.tpl | 51 +++++++++---------- modules/Vtiger/uitypes/Percentage.php | 11 +++- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/layouts/v7/modules/Vtiger/uitypes/Percentage.tpl b/layouts/v7/modules/Vtiger/uitypes/Percentage.tpl index f014114a8..f14abcf81 100644 --- a/layouts/v7/modules/Vtiger/uitypes/Percentage.tpl +++ b/layouts/v7/modules/Vtiger/uitypes/Percentage.tpl @@ -1,28 +1,27 @@ -{*<!-- -/********************************************************************************* - ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 - * ("License"); You may not use this file except in compliance with the License - * The Original Code is: vtiger CRM Open Source - * The Initial Developer of the Original Code is vtiger. - * Portions created by vtiger are Copyright (C) vtiger. - * All Rights Reserved. - * - ********************************************************************************/ --->*} +{*+********************************************************************************** +* The contents of this file are subject to the vtiger CRM Public License Version 1.1 +* ("License"); You may not use this file except in compliance with the License +* The Original Code is: vtiger CRM Open Source +* The Initial Developer of the Original Code is vtiger. +* Portions created by vtiger are Copyright (C) vtiger. +* All Rights Reserved. +*************************************************************************************} + {strip} -{assign var="FIELD_INFO" value=$FIELD_MODEL->getFieldInfo()} -{assign var="SPECIAL_VALIDATOR" value=$FIELD_MODEL->getValidator()} -{if (!$FIELD_NAME)} - {assign var="FIELD_NAME" value=$FIELD_MODEL->getFieldName()} -{/if} -<div class="input-group inputElement"> - <input id="{$MODULE}_editView_fieldName_{$FIELD_NAME}" type="text" class="form-control" name="{$FIELD_NAME}" - value="{$FIELD_MODEL->get('fieldvalue')}" {if !empty($SPECIAL_VALIDATOR)}data-validator='{Zend_Json::encode($SPECIAL_VALIDATOR)}'{/if} step="any" - {if $FIELD_INFO["mandatory"] eq true} data-rule-required="true" {/if} - {if count($FIELD_INFO['validator'])} - data-specific-rules='{ZEND_JSON::encode($FIELD_INFO["validator"])}' - {/if} - /> - <span class="input-group-addon">%</span> -</div> + {assign var="FIELD_INFO" value=$FIELD_MODEL->getFieldInfo()} + {assign var="SPECIAL_VALIDATOR" value=$FIELD_MODEL->getValidator()} + {if (!$FIELD_NAME)} + {assign var="FIELD_NAME" value=$FIELD_MODEL->getFieldName()} + {/if} + {assign var="FIELD_VALUE" value=$FIELD_MODEL->get('fieldvalue')} + <div class="input-group inputElement"> + <input id="{$MODULE}_editView_fieldName_{$FIELD_NAME}" type="text" class="form-control" data-field-id="{$FIELD_MODEL->get('id')}" name="{$FIELD_NAME}" + value="{if !empty($FIELD_VALUE) or $FIELD_VALUE neq NULL}{$FIELD_MODEL->getEditViewDisplayValue($FIELD_VALUE)}{/if}" {if !empty($SPECIAL_VALIDATOR)}data-validator="{Zend_Json::encode($SPECIAL_VALIDATOR)}"{/if} step="any" + {if $FIELD_INFO["mandatory"] eq true} data-rule-required="true" {/if} + {if count($FIELD_INFO['validator'])} + data-specific-rules="{ZEND_JSON::encode($FIELD_INFO["validator"])}" + {/if} + /> + <span class="input-group-addon">%</span> + </div> {/strip} diff --git a/modules/Vtiger/uitypes/Percentage.php b/modules/Vtiger/uitypes/Percentage.php index 9f8e8bd53..4477d8b91 100644 --- a/modules/Vtiger/uitypes/Percentage.php +++ b/modules/Vtiger/uitypes/Percentage.php @@ -18,4 +18,13 @@ class Vtiger_Percentage_UIType extends Vtiger_Base_UIType { return 'uitypes/Percentage.tpl'; } -} \ No newline at end of file + public function getDisplayValue($value, $record = false, $recordInstance = false) { + $fldvalue = str_replace(",", ".", $value); + $value = (is_numeric($fldvalue)) ? $fldvalue : null; + return CurrencyField::convertToUserFormat($value, null, true); + } + + public function getEditViewDisplayValue($value) { + return $this->getDisplayValue($value); + } +} -- GitLab