Welcome to Vtiger Community. To gain access for account, please contact [ info @ vtiger.com ]

Commit 01bbde9bd2f2dd1b6db79e2a1d4646a5f409454f

Authored by Prasad
2 parents 614a9342 2ec85790

Merge branch 'openSource' into 'master'

Ajax edit on currency field showing validation error

Observations:
Spell mistake was happening while validating currency field. Instead of 'decimalSeparator', calling as 'decimalSeperator'.

See merge request !86
include/fields/CurrencyField.php
... ... @@ -430,18 +430,18 @@ class CurrencyField {
430 430 $value = rtrim($value, '0');
431 431 }
432 432 if($user->currency_decimal_separator == ' ')
433   - $decimalSeperator = ' ';
  433 + $decimalSeparator = ' ';
434 434 else
435   - $decimalSeperator = $user->currency_decimal_separator;
  435 + $decimalSeparator = $user->currency_decimal_separator;
436 436  
437   - $fieldValue = explode(decode_html($decimalSeperator), $value);
  437 + $fieldValue = explode(decode_html($decimalSeparator), $value);
438 438 if(strlen($fieldValue[1]) <= 1){
439 439 if(strlen($fieldValue[1]) == 1) {
440   - return $value = $fieldValue[0].$decimalSeperator.$fieldValue[1];
  440 + return $value = $fieldValue[0].$decimalSeparator.$fieldValue[1];
441 441 } else if (!strlen($fieldValue[1])) {
442 442 return $value = $fieldValue[0];
443 443 } else {
444   - return $value = $fieldValue[0].$decimalSeperator;
  444 + return $value = $fieldValue[0].$decimalSeparator;
445 445 }
446 446 }else{
447 447 return preg_replace("/(?<=\\.[0-9])[0]+\$/","",$value);
... ...
layouts/vlayout/modules/Products/resources/Edit.js
... ... @@ -110,7 +110,7 @@ Vtiger_Edit_Js(&quot;Products_Edit_Js&quot;,{
110 110 var price = parseFloat(unitPrice) * parseFloat(conversionRate);
111 111 var userPreferredDecimalPlaces = unitPriceFieldData.numberOfDecimalPlaces;
112 112 price = price.toFixed(userPreferredDecimalPlaces);
113   - var calculatedPrice = price.toString().replace('.',unitPriceFieldData.decimalSeperator);
  113 + var calculatedPrice = price.toString().replace('.',unitPriceFieldData.decimalSeparator);
114 114 jQuery('.convertedPrice',parentElem).val(calculatedPrice);
115 115 });
116 116 return this;
... ... @@ -128,9 +128,9 @@ Vtiger_Edit_Js(&quot;Products_Edit_Js&quot;,{
128 128 var fieldData = field.data();
129 129 //As replace is doing replace of single occurence and using regex
130 130 //replace has a problem with meta characters like (.,$),so using split and join
131   - var strippedValue = unitPrice.split(fieldData.groupSeperator);
  131 + var strippedValue = unitPrice.split(fieldData.groupSeparator);
132 132 strippedValue = strippedValue.join("");
133   - strippedValue = strippedValue.replace(fieldData.decimalSeperator, '.');
  133 + strippedValue = strippedValue.replace(fieldData.decimalSeparator, '.');
134 134 unitPrice = strippedValue;
135 135 }
136 136 return unitPrice;
... ... @@ -176,7 +176,7 @@ Vtiger_Edit_Js(&quot;Products_Edit_Js&quot;,{
176 176 jQuery('button.currencyReset', parentRow).attr('disabled', true).removeAttr('disabled');
177 177 var userPreferredDecimalPlaces = unitPriceFieldData.numberOfDecimalPlaces;
178 178 price = price.toFixed(userPreferredDecimalPlaces);
179   - var calculatedPrice = price.toString().replace('.',unitPriceFieldData.decimalSeperator);
  179 + var calculatedPrice = price.toString().replace('.',unitPriceFieldData.decimalSeparator);
180 180 jQuery('input.convertedPrice',parentRow).val(calculatedPrice)
181 181 }else{
182 182 jQuery('input',parentRow).attr('disabled', true);
... ...
layouts/vlayout/modules/Settings/Webforms/resources/Field.js
... ... @@ -108,7 +108,7 @@ Vtiger_Field_Js(&#39;Webforms_Currency_Field_Js&#39;,{},{
108 108 getUi : function() {
109 109 var html = '<div class="input-prepend">'+
110 110 '<span class="add-on">'+ this.getCurrencySymbol()+'</span>'+
111   - '<input type="text" name="'+ this.getName() +'" value="'+ this.getValue() + '" class="input-medium" style="width:210px" data-decimal-separator="'+this.getData().decimalSeperator+'" data-group-separator="'+this.getData().groupSeperator+'"/>'+
  111 + '<input type="text" name="'+ this.getName() +'" value="'+ this.getValue() + '" class="input-medium" style="width:210px" data-decimal-separator="'+this.getData().decimalSeparator+'" data-group-separator="'+this.getData().groupSeparator+'"/>'+
112 112 '</div>';
113 113 var element = jQuery(html);
114 114 return this.addValidationToElement(element);
... ...
layouts/vlayout/modules/Users/resources/Edit.js
... ... @@ -67,9 +67,9 @@ Vtiger_Edit_Js(&quot;Users_Edit_Js&quot;,{},{
67 67 registerRecordPreSaveEvent : function(form){
68 68 var thisInstance = this;
69 69 form.on(Vtiger_Edit_Js.recordPreSave, function(e, data) {
70   - var groupingSeperatorValue = jQuery('[name="currency_grouping_separator"]', form).val();
71   - var decimalSeperatorValue = jQuery('[name="currency_decimal_separator"]', form).val();
72   - if(groupingSeperatorValue == decimalSeperatorValue){
  70 + var groupingSeparatorValue = jQuery('[name="currency_grouping_separator"]', form).val();
  71 + var decimalSeparatorValue = jQuery('[name="currency_decimal_separator"]', form).val();
  72 + if(groupingSeparatorValue == decimalSeparatorValue){
73 73 Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_DECIMAL_SEPARATOR_AND_GROUPING_SEPARATOR_CANT_BE_SAME'));
74 74 e.preventDefault();
75 75 }
... ...
layouts/vlayout/modules/Users/resources/PreferenceDetail.js
... ... @@ -14,6 +14,6 @@ Users_Detail_Js(&quot;Users_PreferenceDetail_Js&quot;,{},{
14 14 */
15 15 registerEvents : function(){
16 16 this._super();
17   - Users_PreferenceEdit_Js.registerChangeEventForCurrencySeperator();
  17 + Users_PreferenceEdit_Js.registerChangeEventForCurrencySeparator();
18 18 }
19 19 });
20 20 \ No newline at end of file
... ...
layouts/vlayout/modules/Users/resources/PreferenceEdit.js
... ... @@ -12,13 +12,13 @@ Users_Edit_Js(&quot;Users_PreferenceEdit_Js&quot;,{
12 12 /**
13 13 * Function to register change event for currency separator
14 14 */
15   - registerChangeEventForCurrencySeperator : function(){
  15 + registerChangeEventForCurrencySeparator : function(){
16 16 var form = jQuery('form');
17 17 jQuery('[name="currency_decimal_separator"]',form).on('change',function(e){
18 18 var element = jQuery(e.currentTarget);
19 19 var selectedValue = element.val();
20   - var groupingSeperatorValue = jQuery('[name="currency_grouping_separator"]',form).data('selectedValue');
21   - if(groupingSeperatorValue == selectedValue){
  20 + var groupingSeparatorValue = jQuery('[name="currency_grouping_separator"]',form).data('selectedValue');
  21 + if(groupingSeparatorValue == selectedValue){
22 22 var message = app.vtranslate('JS_DECIMAL_SEPARATOR_AND_GROUPING_SEPARATOR_CANT_BE_SAME');
23 23 var params = {
24 24 text: message,
... ... @@ -36,8 +36,8 @@ Users_Edit_Js(&quot;Users_PreferenceEdit_Js&quot;,{
36 36 jQuery('[name="currency_grouping_separator"]',form).on('change',function(e){
37 37 var element = jQuery(e.currentTarget);
38 38 var selectedValue = element.val();
39   - var decimalSeperatorValue = jQuery('[name="currency_decimal_separator"]',form).data('selectedValue');
40   - if(decimalSeperatorValue == selectedValue){
  39 + var decimalSeparatorValue = jQuery('[name="currency_decimal_separator"]',form).data('selectedValue');
  40 + if(decimalSeparatorValue == selectedValue){
41 41 var message = app.vtranslate('JS_DECIMAL_SEPARATOR_AND_GROUPING_SEPARATOR_CANT_BE_SAME');
42 42 var params = {
43 43 text: message,
... ... @@ -60,6 +60,6 @@ Users_Edit_Js(&quot;Users_PreferenceEdit_Js&quot;,{
60 60 */
61 61 registerEvents : function(){
62 62 this._super();
63   - Users_PreferenceEdit_Js.registerChangeEventForCurrencySeperator();
  63 + Users_PreferenceEdit_Js.registerChangeEventForCurrencySeparator();
64 64 }
65 65 });
66 66 \ No newline at end of file
... ...
modules/Vtiger/resources/validator/FieldValidator.js
... ... @@ -620,16 +620,16 @@ Vtiger_Base_Validator_Js(&#39;Vtiger_Currency_Validator_Js&#39;,{
620 620 var fieldValue = this.getFieldValue();
621 621 var fieldData = field.data();
622 622  
623   - var strippedValue = fieldValue.replace(fieldData.decimalSeperator, '');
  623 + var strippedValue = fieldValue.replace(fieldData.decimalSeparator, '');
624 624 var spacePattern = /\s/;
625   - if(spacePattern.test(fieldData.decimalSeperator) || spacePattern.test(fieldData.groupSeperator))
  625 + if(spacePattern.test(fieldData.decimalSeparator) || spacePattern.test(fieldData.groupSeparator))
626 626 strippedValue = strippedValue.replace(/ /g, '');
627 627 var errorInfo;
628 628  
629   - if(fieldData.groupSeperator =="$"){
630   - fieldData.groupSeperator="\\$"
  629 + if(fieldData.groupSeparator =="$"){
  630 + fieldData.groupSeparator="\\$"
631 631 }
632   - var regex = new RegExp(fieldData.groupSeperator,'g');
  632 + var regex = new RegExp(fieldData.groupSeparator,'g');
633 633 strippedValue = strippedValue.replace(regex, '');
634 634 //Note: Need to review if we should allow only positive values in currencies
635 635 /*if(strippedValue < 0){
... ...
pkg/vtiger/modules/Webforms/settings/models/ModuleField.php
... ... @@ -51,8 +51,8 @@ class Settings_Webforms_ModuleField_Model extends Vtiger_Field_Model {
51 51 if($this->getFieldDataType() == 'currency') {
52 52 $currentUser = Users_Record_Model::getCurrentUserModel();
53 53 $fieldInfo['currency_symbol'] = $currentUser->get('currency_symbol');
54   - $fieldInfo['decimalSeperator'] = $currentUser->get('currency_decimal_separator');
55   - $fieldInfo['groupSeperator'] = $currentUser->get('currency_grouping_separator');
  54 + $fieldInfo['decimalSeparator'] = $currentUser->get('currency_decimal_separator');
  55 + $fieldInfo['groupSeparator'] = $currentUser->get('currency_grouping_separator');
56 56 }
57 57  
58 58 if($this->getFieldDataType() == 'owner') {
... ...
pkg/vtiger/modules/Webforms/settings/models/Record.php
... ... @@ -338,10 +338,10 @@ class Settings_Webforms_Record_Model extends Settings_Vtiger_Record_Model {
338 338 }
339 339  
340 340 if ($dataType === 'currency') {
341   - $decimalSeperator = $currentUser->get('currency_decimal_separator');
342   - $groupSeperator = $currentUser->get('currency_grouping_separator');
343   - $fieldDefaultValue = str_replace($decimalSeperator, '.', $fieldDefaultValue);
344   - $fieldDefaultValue = str_replace($groupSeperator, '', $fieldDefaultValue);
  341 + $decimalSeparator = $currentUser->get('currency_decimal_separator');
  342 + $groupSeparator = $currentUser->get('currency_grouping_separator');
  343 + $fieldDefaultValue = str_replace($decimalSeparator, '.', $fieldDefaultValue);
  344 + $fieldDefaultValue = str_replace($groupSeparator, '', $fieldDefaultValue);
345 345 }
346 346  
347 347 array_push($params, $fieldName, $neutralizedField, $fieldDefaultValue, $fieldDetails['required'], $fieldDetails['sequence'], $fieldDetails['hidden']);
... ...
pkg/vtiger/modules/Webforms/settings/templates/resources/Field.js
... ... @@ -108,7 +108,7 @@ Vtiger_Field_Js(&#39;Webforms_Currency_Field_Js&#39;,{},{
108 108 getUi : function() {
109 109 var html = '<div class="input-prepend">'+
110 110 '<span class="add-on">'+ this.getCurrencySymbol()+'</span>'+
111   - '<input type="text" name="'+ this.getName() +'" value="'+ this.getValue() + '" class="input-medium" style="width:210px" data-decimal-separator="'+this.getData().decimalSeperator+'" data-group-separator="'+this.getData().groupSeperator+'"/>'+
  111 + '<input type="text" name="'+ this.getName() +'" value="'+ this.getValue() + '" class="input-medium" style="width:210px" data-decimal-separator="'+this.getData().decimalSeparator+'" data-group-separator="'+this.getData().groupSeparator+'"/>'+
112 112 '</div>';
113 113 var element = jQuery(html);
114 114 return this.addValidationToElement(element);
... ...