Skip to content

Commit

Permalink
feat ariatemplates#964 Changes for Error tooltip on keydown
Browse files Browse the repository at this point in the history
  • Loading branch information
smadapathi committed Feb 12, 2014
1 parent 19936ea commit 70ba84a
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/aria/widgets/CfgBeans.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Aria.beanDefinitions({
},
"validationEvent" : {
$type : "json:Enum",
$enumValues : ["onFocus", "onBlur", "none"],
$enumValues : ["onFocus", "onBlur", "onError", "none"],
$default : "onFocus",
$description : "contains the event used to display the error tip"
},
Expand Down
1 change: 1 addition & 0 deletions src/aria/widgets/controllers/AutoCompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
} else {
if (!this.freeText && suggestionsAvailable && !hasSuggestions) {
report.ok = false;
report.errorMessages.push(this.res.errors["40020_WIDGET_AUTOCOMPLETE_VALIDATION"]);
} else {
report.ok = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/aria/widgets/controllers/MultiAutoCompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
dataModel.value = null;
report.ok = true;
reportVal = null;
} else if (value && !typeUtil.isString(value)) {
} else if (value && !typeUtil.isString(value) && dataModel.value !== null) {
if (this._checkWithSuggestionBean(value, this._resourcesHandler.SUGGESTION_BEAN)) {
var text = this._getLabelFromSuggestion(value);
dataModel.text = text;
Expand Down Expand Up @@ -296,6 +296,7 @@
} else {
if (!this.freeText && suggestionsAvailable && !hasSuggestions) {
report.ok = false;
report.errorMessages.push(this.res.errors["40020_WIDGET_AUTOCOMPLETE_VALIDATION"]);
} else {
report.ok = true;
}
Expand Down
1 change: 0 additions & 1 deletion src/aria/widgets/form/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ Aria.classDefinition({
// environment
cfg.directOnBlurValidation = aria.widgets.environment.WidgetSettings.getWidgetSettings().directOnBlurValidation;
}

if (cfg.height > -1) {
this._inputMarkupHeight = cfg.height;

Expand Down
10 changes: 5 additions & 5 deletions src/aria/widgets/form/MultiAutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Aria.classDefinition({
$classpath : "aria.widgets.form.MultiAutoComplete",
$extends : "aria.widgets.form.AutoComplete",
$dependencies : ["aria.widgets.controllers.MultiAutoCompleteController", "aria.utils.Event", "aria.utils.Dom",
"aria.utils.Type", "aria.utils.Array", "aria.utils.Math"],
"aria.utils.Type", "aria.utils.Array", "aria.utils.Math", "aria.utils.String"],
$css : ["aria.widgets.form.MultiAutoCompleteStyle", "aria.widgets.form.list.ListStyle",
"aria.widgets.container.DivStyle"],
/**
Expand Down Expand Up @@ -85,7 +85,6 @@ Aria.classDefinition({
if (report && report.value !== null) {
this._addMultiselectValues(report, arg);
}

},

/**
Expand Down Expand Up @@ -269,13 +268,15 @@ Aria.classDefinition({
var inputField = this.getTextInputField();
var inputFieldValue = inputField.value;
var domUtil = aria.utils.Dom;
if (tabPressed && inputFieldValue !== "") {
var stringUtil = aria.utils.String;
if (tabPressed && stringUtil.trim(inputFieldValue) !== "" && this.controller.freeText) {
event.preventDefault();
var report = this.controller.checkText(inputFieldValue, false);
this._reactToControllerReport(report);
this.setHelpText(false);
inputField.focus();
}
if (tabPressed && inputFieldValue === "" && inputField.nextSibling != null) {
if (tabPressed && stringUtil.trim(inputFieldValue) === "" && inputField.nextSibling != null) {
event.preventDefault();
this._makeInputFieldLastChild();
this.setHelpText(false);
Expand All @@ -292,7 +293,6 @@ Aria.classDefinition({
domUtil.removeElement(previousSiblingElement);
this._removeValues(previousSiblingLabel);
}

}
this.$DropDownTextInput._dom_onkeydown.call(this, event);
},
Expand Down
15 changes: 11 additions & 4 deletions src/aria/widgets/form/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,6 @@ Aria.classDefinition({
if (!performCheckOnly) {
this.changeProperty("value", null);
this.changeProperty("invalidText", text);
if (this._cfg.directOnBlurValidation) {
this.changeProperty("formatErrorMessages", report.errorMessages);
}
}
} else if (this._cfg.formatError === false && aria.utils.Type.isArray(this._cfg.formatErrorMessages)
&& this._cfg.formatErrorMessages.length) {
Expand Down Expand Up @@ -508,6 +505,9 @@ Aria.classDefinition({
}

}
if (report.errorMessages.length && this._cfg.directOnBlurValidation) {
this.changeProperty("formatErrorMessages", report.errorMessages);
}
// if the validation originated from a validation with delay we
// do not want to update the input text or
// value. The value will be set to 'undefined' though when the
Expand Down Expand Up @@ -711,6 +711,14 @@ Aria.classDefinition({
|| propertyName === 'errorMessages') {
this._cfg[propertyName] = newValue;
this._reactToChange();
var cfg = this._cfg;
if (cfg && cfg.validationEvent === 'onError' && (this._keepFocus || this._hasFocus)) {
if ((cfg.formatError && cfg.formatErrorMessages.length) || (cfg.error && cfg.errorMessages.length)) {
this._validationPopupShow();
} else {
this._validationPopupHide();
}
}
} else if (propertyName == "prefill") {
this.setPrefillText(true, newValue, true);
} else if (propertyName == "prefillError") {
Expand Down Expand Up @@ -812,7 +820,6 @@ Aria.classDefinition({
this.checkValue();
}
},

/**
* Internal method to handle the onkeyup event. This is called to set the value property in the data model
* through the setProperty method that also handles all other widgets bound to this value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ Aria.classDefinition({
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test7.MultiAutoError");
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test8.MultiAutoMaxOptions");
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test9.MultiAutoBackSpace");
this.addTests("test.aria.widgets.form.autocomplete.errorhandling.AutoComplete");
}
});
65 changes: 65 additions & 0 deletions test/aria/widgets/form/autocomplete/errorhandling/AutoComplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2013 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Aria.classDefinition({
$classpath : "test.aria.widgets.form.autocomplete.errorhandling.AutoComplete",
$extends : "aria.jsunit.TemplateTestCase",
$prototype : {
/**
* This method is always the first entry point to a template test Start the test by focusing the first field.
* Initially give the field focus.
*/
runTemplateTest : function () {
this.synEvent.click(this.getInputField("acDest"), {
fn : this.onAcFocused,
scope : this
});
},

/**
* Field should have focus, next trigger an exact match.
*/
onAcFocused : function () {
this.synEvent.type(this.getInputField("acDest"), "z", {
fn : this.waitForType,
scope : this
});
},

/**
* Need to add a delay to allow the list to open with the returned suggestions including the exact match.
*/
waitForType : function () {
this.waitFor({
condition : function () {
return (this.getWidgetInstance("acDest")._state == "normalErrorFocused");
},
callback : {
fn : this.checkErrorTooltip,
scope : this
}
});
},
/**
* Finalize the test, check the bound widgets value has been updated by a change to the data model when the
* enter key was triggered.
*/
checkErrorTooltip : function () {
var acWidget = this.getWidgetInstance("acDest");
this.assertTrue(!!acWidget._onValidatePopup);
this.notifyTemplateTestEnd();
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2013 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

{Template {
$classpath:"test.aria.widgets.form.autocomplete.errorhandling.AutoCompleteTpl",
$hasScript:true,
$width: {min: 500}
}}

{var view_values = {
ac_air_value: null
}/}


{macro main()}
<h2>AutoComplete with LC resources handler</h2> <br />

{@aria:AutoComplete {
id: "acDest",
label:"Choose your destination: ",
labelPos:"left",
labelAlign:"right",
width:400,
block:false,
labelWidth:180,
validationEvent:'onError',
freeText:false,
resourcesHandler:_getCitiesHandler()
}/}

{/macro}

{/Template}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2013 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Aria.tplScriptDefinition({
$classpath : "test.aria.widgets.form.autocomplete.errorhandling.AutoCompleteTplScript",
$dependencies : ["aria.resources.handlers.LCResourcesHandler"],
$constructor : function () {
this._lcHandler = new aria.resources.handlers.LCResourcesHandler();
this._lcHandler.setSuggestions([{
label : 'Madrid',
code : 'MAD'
}, {
label : 'Rio de Janeiro',
code : 'RIO'
}, {
label : 'Miami',
code : 'MIA'
}]);
},
$destructor : function () {
this._lcHandler.$dispose();
this._lcHandler = null;
},
$prototype : {
_getCitiesHandler : function () {
return this._lcHandler;
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Aria.classDefinition({
* This method is always the first entry point to a template test Start the test by focusing the first field
*/
runTemplateTest : function () {

this.synEvent.click(this.getInputField("MultiAutoId"), {
fn : this.typeSomething,
scope : this
Expand All @@ -43,23 +44,28 @@ Aria.classDefinition({

typeSomething : function (evt, callback) {
// give it the time to open a drop down
this.synEvent.type(this.getInputField("MultiAutoId"), "sdafwerew", {
fn : this._wait,
this.synEvent.type(this.getInputField("MultiAutoId"), "az", {
fn : this._waitForType,
scope : this,
args : this._assertErrorState
});
},
_wait : function (evt, callback) {
aria.core.Timer.addCallback({
fn : callback,
scope : this,
delay : 500
_waitForType : function () {
var acWidget = this.getWidgetInstance("MultiAutoId");
this.waitFor({
condition : function () {
return (acWidget._state == "normalErrorFocused");
},
callback : {
fn : this._assertErrorState,
scope : this
}
});
},
_assertErrorState : function () {
// test that the field is in error state
var acWidget = this.getWidgetInstance("MultiAutoId");
this.assertTrue(acWidget._state == "normalErrorFocused", "The auto-complete should be in the normalErrorFocused state.");
this.assertTrue(!!acWidget._onValidatePopup);
this.notifyTemplateTestEnd();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
$hasScript:true
}}




{macro main()}

<h2>AutoComplete with Multi Options</h2>
<br />
{@aria:MultiAutoComplete{
label:"Choose your city: ",
helptext:"city",
id:"MultiAutoId",
labelPos:"left",
validationEvent:'onError',
labelAlign:"right",
width:400,
block:false,
Expand Down

0 comments on commit 70ba84a

Please sign in to comment.