Skip to content

Commit

Permalink
feat Customization of widget's error messages
Browse files Browse the repository at this point in the history
It is now possible for a user to customize the error messages used by the widgets.

There are 3 levels of error messages specifications, the two firsts being user configuration while the last is the hardcoded default.

This is resolved in this order of precedence:

- local: widget's configuration
- global: application's environment
- hardcoded: widget's resources
  • Loading branch information
ymeine committed Mar 13, 2015
1 parent ea17000 commit bbdbfe4
Show file tree
Hide file tree
Showing 22 changed files with 749 additions and 43 deletions.
86 changes: 86 additions & 0 deletions src/aria/widgets/CfgBeans.js
Expand Up @@ -538,8 +538,33 @@ module.exports = Aria.beanDefinitions({
$properties : {
"referenceDate" : {
$type : "common:BindingRef"
},
"defaultErrorMessages" : {
$type : "common:BindingRef"
}
}
},
"defaultErrorMessages" : {
$type : "json:Object",
$description : "Default values for error messages.",
$properties : {
"validation" : {
$type : "json:String",
$description : "Default message for validation error.",
$default : null
},
"minValue": {
$type : "json:String",
$description : "Default message for minimum value validation error.",
$default : null
},
"maxValue": {
$type : "json:String",
$description : "Default message for maximum value validation error.",
$default : null
}
},
$default : {}
}
}
},
Expand All @@ -551,6 +576,26 @@ module.exports = Aria.beanDefinitions({
"pattern" : {
$type : "environmentBase:FormatTypes",
$description : "Time pattern used to generate a value for the time entry"
},
"bind" : {
$type : "TextInputCfg.bind",
$properties : {
"defaultErrorMessages" : {
$type : "common:BindingRef"
}
}
},
"defaultErrorMessages" : {
$type : "json:Object",
$description : "Default values for error messages.",
$properties : {
"validation" : {
$type : "json:String",
$description : "Default message for validation error.",
$default : null
}
},
$default : {}
}
}
},
Expand All @@ -571,9 +616,30 @@ module.exports = Aria.beanDefinitions({
$type : "json:Float",
$description : ""
}]
},
"bind" : {
$type : "TextInputCfg.bind",
$properties : {
"defaultErrorMessages" : {
$type : "common:BindingRef"
}
}
},
"defaultErrorMessages" : {
$type : "json:Object",
$description : "Default values for error messages.",
$properties : {
"validation" : {
$type : "json:String",
$description : "Default message for validation error.",
$default : null
}
},
$default : {}
}
}
},

"DropDownTextInputCfg" : {
$type : "TextInputCfg",
$description : "The base configuration for any widget extending DropDownInput",
Expand Down Expand Up @@ -977,6 +1043,26 @@ module.exports = Aria.beanDefinitions({
$default : [{
key : "ENTER"
}]
},
"bind" : {
$type : "DropDownTextInputCfg.bind",
$properties : {
"defaultErrorMessages" : {
$type : "common:BindingRef"
}
}
},
"defaultErrorMessages" : {
$type : "json:Object",
$description : "Default values for error messages.",
$properties : {
"validation" : {
$type : "json:String",
$description : "Default message for validation error.",
$default : null
}
},
$default : {}
}
}
},
Expand Down
22 changes: 14 additions & 8 deletions src/aria/widgets/WidgetsRes.js
Expand Up @@ -20,16 +20,22 @@ Aria.resourcesDefinition({
$classpath : 'aria.widgets.WidgetsRes',
$resources : {
errors : {
"40006_WIDGET_NUMBERFIELD_VALIDATION" : "Number field must be a numerical value.",
"40007_WIDGET_TIMEFIELD_VALIDATION" : "Please enter a valid time format, for example: 1000 or 10:00",
"NumberField" : {
"validation" : "Number field must be a numerical value."
},
"TimeField" : {
"validation" : "Please enter a valid time format, for example: 1000 or 10:00"
},
// For PTR 04203167, we must ensure that the error message below (for date validation) does not contain
// formats unsuitable for booking a flight (e.g. date in the past like -5)
"40008_WIDGET_DATEFIELD_VALIDATION" : "Please enter a valid date format, for example: 10/12 or 01MAR or +4",
"40018_WIDGET_DATEFIELD_MINVALUE" : "Date is before the minimum date.",
"40019_WIDGET_DATEFIELD_MAXVALUE" : "Date is after the maximum date.",
"40020_WIDGET_AUTOCOMPLETE_VALIDATION" : "There is no suggestion available for the given entry.",

"" : "" // empty entry to use commas at the end of each error description (!)
"DateField" : {
"validation" : "Please enter a valid date format, for example: 10/12 or 01MAR or +4",
"minValue" : "Date is before the minimum date.",
"maxValue" : "Date is after the maximum date."
},
"AutoComplete" : {
"validation" : "There is no suggestion available for the given entry."
}
}
}
});
11 changes: 4 additions & 7 deletions src/aria/widgets/controllers/AutoCompleteController.js
Expand Up @@ -19,7 +19,6 @@ var ariaTemplatesRefreshManager = require("../../templates/RefreshManager");
var ariaWidgetsControllersReportsDropDownControllerReport = require("./reports/DropDownControllerReport");
var ariaUtilsType = require("../../utils/Type");
var ariaHtmlControllersSuggestions = require("../../html/controllers/Suggestions");
var ariaWidgetsWidgetsRes = require("../../$resources").file(__dirname, "../WidgetsRes");
var ariaWidgetsControllersDropDownListController = require("./DropDownListController");
var ariaCoreJsonValidator = require("../../core/JsonValidator");

Expand All @@ -35,16 +34,15 @@ var ariaCoreJsonValidator = require("../../core/JsonValidator");
module.exports = Aria.classDefinition({
$classpath : "aria.widgets.controllers.AutoCompleteController",
$extends : ariaWidgetsControllersDropDownListController,
$resources : {
res : ariaWidgetsWidgetsRes
},
$onload : function () {
typeUtil = ariaUtilsType;
},
$onunload : function () {
typeUtil = null;
},
$constructor : function () {
this._widgetName = "AutoComplete";

this.$DropDownListController.constructor.call(this);

/**
Expand Down Expand Up @@ -174,7 +172,7 @@ var ariaCoreJsonValidator = require("../../core/JsonValidator");
} else {
report.ok = false;
report.value = null;
report.errorMessages.push(this.res.errors["40020_WIDGET_AUTOCOMPLETE_VALIDATION"]);
report.errorMessages.push(this.getErrorMessage("validation"));
}
}

Expand Down Expand Up @@ -388,7 +386,7 @@ var ariaCoreJsonValidator = require("../../core/JsonValidator");
} else {
if (!this.freeText && suggestionsAvailable && !hasSuggestions) {
report.ok = false;
report.errorMessages.push(this.res.errors["40020_WIDGET_AUTOCOMPLETE_VALIDATION"]);
report.errorMessages.push(this.getErrorMessage("validation"));
} else {
report.ok = true;
}
Expand Down Expand Up @@ -526,7 +524,6 @@ var ariaCoreJsonValidator = require("../../core/JsonValidator");
}
return specialKey;
}

}
});
})();
11 changes: 4 additions & 7 deletions src/aria/widgets/controllers/DateController.js
Expand Up @@ -17,17 +17,14 @@ var ariaWidgetsControllersReportsControllerReport = require("./reports/Controlle
var ariaUtilsDate = require("../../utils/Date");
var ariaUtilsType = require("../../utils/Type");
var ariaUtilsEnvironmentDate = require("../../utils/environment/Date");
var ariaWidgetsWidgetsRes = require("../../$resources").file(__dirname, "../WidgetsRes");
var ariaWidgetsControllersTextDataController = require("./TextDataController");


module.exports = Aria.classDefinition({
$classpath : "aria.widgets.controllers.DateController",
$extends : ariaWidgetsControllersTextDataController,
$resources : {
"res" : ariaWidgetsWidgetsRes
},
$constructor : function () {
this._widgetName = "DateField";

this.$TextDataController.constructor.call(this);

Expand Down Expand Up @@ -150,10 +147,10 @@ module.exports = Aria.classDefinition({
internalValue = ariaUtilsDate.removeTime(internalValue);
if (this._minValue && internalValue < this._minValue) {
report.ok = false;
report.errorMessages.push(this.res.errors["40018_WIDGET_DATEFIELD_MINVALUE"]);
report.errorMessages.push(this.getErrorMessage("minValue"));
} else if (this._maxValue && internalValue > this._maxValue) {
report.ok = false;
report.errorMessages.push(this.res.errors["40019_WIDGET_DATEFIELD_MAXVALUE"]);
report.errorMessages.push(this.getErrorMessage("maxValue"));
} else {
report.ok = true;
this._dataModel.jsDate = internalValue;
Expand Down Expand Up @@ -196,7 +193,7 @@ module.exports = Aria.classDefinition({
} else {
report = new ariaWidgetsControllersReportsControllerReport();
report.ok = false;
report.errorMessages.push(this.res.errors["40008_WIDGET_DATEFIELD_VALIDATION"]);
report.errorMessages.push(this.getErrorMessage("validation"));
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/aria/widgets/controllers/NumberController.js
Expand Up @@ -16,7 +16,6 @@ var Aria = require("../../Aria");
var ariaWidgetsControllersReportsControllerReport = require("./reports/ControllerReport");
var ariaUtilsNumber = require("../../utils/Number");
var ariaCoreJsonValidator = require("../../core/JsonValidator");
var ariaWidgetsWidgetsRes = require("../../$resources").file(__dirname, "../WidgetsRes");
var ariaWidgetsControllersTextDataController = require("./TextDataController");
var ariaUtilsType = require("../../utils/Type");

Expand All @@ -27,10 +26,9 @@ var ariaUtilsType = require("../../utils/Type");
module.exports = Aria.classDefinition({
$classpath : "aria.widgets.controllers.NumberController",
$extends : ariaWidgetsControllersTextDataController,
$resources : {
"res" : ariaWidgetsWidgetsRes
},
$constructor : function () {
this._widgetName = "NumberField";

this.$TextDataController.constructor.call(this);

/**
Expand Down Expand Up @@ -117,7 +115,7 @@ module.exports = Aria.classDefinition({
// Nothing changed
report.ok = !hasErrors;
if (!report.ok) {
report.errorMessages[0] = this.res.errors["40006_WIDGET_NUMBERFIELD_VALIDATION"];
report.errorMessages[0] = this.getErrorMessage("validation");
}
} else {
// Update the text datamodel
Expand All @@ -133,7 +131,7 @@ module.exports = Aria.classDefinition({

report.ok = true;
} else {
report.errorMessages[0] = this.res.errors["40006_WIDGET_NUMBERFIELD_VALIDATION"];
report.errorMessages[0] = this.getErrorMessage("validation");
// The text doesn't correspond to a valid number
this._dataModel.number = null;
}
Expand Down

0 comments on commit bbdbfe4

Please sign in to comment.