Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

feat #914 MultiAutoComplete Widget with more changes #915

Closed
wants to merge 1 commit into from

2 participants

@smadapathi

This pull request allows the following features

1) User can add suggestion on "Enter" key press
2) Suggestion can be deleted on "Backspace" key
3) On "Tab" key, focus goes to input back again
4) Match at word boundaries
5) Ellipsis for the long suggestion
and some minor fixes.

@divdavem divdavem was assigned
...ia/widgets/controllers/MultiAutoCompleteController.js
@@ -116,7 +120,9 @@
addedValue = text;
}
this._suggestionToBeAdded = addedValue;
- if (this.selectedSuggestions.length > 0 && !init) {
+ if (this.maxOptions && this.selectedSuggestions.length < this.maxOptions && !init) {
+ addedValue = this._checkValidSuggestion(addedValue);
+ } else {
addedValue = this._checkValidSuggestion(addedValue);
}
@divdavem Collaborator

When you write code, please simplify it as much as possible...
If you do the same thing both when a condition is true and when it is false, you probably don't need the condition. Instead of:

if (a) {
   b();
} else {
   b();
}

Please use simply:

b();

(which is strictly equivalent only if evaluating condition a has no side effect, which is the case here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/aria/resources/handlers/LCRangeResourceHandler.js
@@ -89,21 +91,34 @@
codeSuggestions.push(suggestion.original);
suggestion.original.exactMatch = false;
} else {
- if (suggestion.label.substring(0, textEntryLength) === textEntry) {
+ var boundaries = multiWord ? suggestion.wordBoundaries : [0];
+ for (var j = 0, len = boundaries.length, boundary; j < len; j++) {
+ boundary = boundaries[j];
+ if (suggestion.label.substring(boundary, boundary + textEntryLength) !== textEntry) {
+ continue;
+ }
+
@divdavem Collaborator

All this code is very similar to (and probably copy-pasted from) the LCResourcesHandler

Instead of copy-pasting, please consider sharing code when it makes sense.

An LCRangeResourcesHandler instance is basically doing the same job as an LCResourcesHandler instance except that it is also able to support ranges. So, in the code of the LCRangeResourcesHandler, you should only find code to manage ranges, and everything else should be delegated somehow to the parent.

In the previous pull request about the multi-autocomplete (see here), I already suggested you to call the parent getSuggestions method from this method.
Later, you were asked to support something the parent getSuggestions method already supported.
If you had followed my advice, support for multi-word matching would have been present right from the beginning in LCRangeResourcesHandler.
Sharing code allows to automatically benefit from features and bug fixes implemented in the common code.

So, basically, here, the whole prototype of LCRangeResourcesHandler could be as simple as the following code (perhaps this code would have to be adapted a bit, I have written it here only for you to understand the idea):

        $prototype : {

            rangePattern : /^[a-z]{1}\d+-\d+/,

            getSuggestions : function (textEntry, callback) {
                if (!typesUtil.isString(textEntry) || textEntry.length < this.threshold) {
                    this.$callback(callback, null);
                    return;
                }
                textEntry = stringUtil.stripAccents(textEntry).toLowerCase();
                if (this.allowRangeValues && this.rangePattern.test(textEntry)) {
                    var firstLetter = textEntry.charAt(0);
                    var rangeV = textEntry.substring(1).split("-");
                    var results = {
                        suggestions : [],
                        multipleValues : true
                    };
                    for (var k = rangeV[0]; k <= rangeV[1]; k++) {
                        var textEntry = firstLetter + k;
                        this.$LCResourcesHandler.getSuggestions.call(this, textEntry, {
                            fn : this.__appendSuggestions,
                            scope : this,
                            args : results
                        });
                    }
                    this.$callback(callback, results);
                } else {
                    this.$LCResourcesHandler.getSuggestions.call(this, textEntry, callback);
                }
            },

            __appendSuggestions : function (suggestions, results) {
                if (suggestions) {
                    results.suggestions = results.suggestions.concat(suggestions);
                }
            }

        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/aria/widgets/form/MultiAutoComplete.js
((29 lines not shown))
this._editMultiselectValue(element, event);
}
}
},
/**
+ * Handling blur event
+ * @param {aria.utils.Event} event
+ * @protected
+ */
+ _dom_onblur : function (event) {
+ var inputField = this.getTextInputField();
+ if (inputField.parentNode.lastChild.nodeName !== "INPUT" && inputField.value === "") {
@divdavem Collaborator

Instead of this complex condition, you could use the nextSibling property to know whether the input field is the last child of its parent. So the condition would become:

if (inputField.nextSibling != null && inputField.value === "") {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/aria/widgets/form/MultiAutoComplete.js
((42 lines not shown))
+ }
+ this.$TextInput._dom_onblur.call(this, event);
+ },
+ /**
+ * Make the inputfield as last child of widget
+ * @protected
+ */
+ _makeInputFieldLastChild : function () {
+ var domUtil = aria.utils.Dom;
+ if (this._frame.getChild(0).lastChild !== this._textInputField) {
+ domUtil.insertAdjacentHTML(this._frame.getChild(0).lastChild, "afterEnd", "<span></span>");
+ domUtil.replaceDomElement(this._frame.getChild(0).lastChild, this._textInputField);
+ this._textInputField.style.width = "0px";
+ this.__resizeInput();
+ this.setHelpText(false);
+ this._textInputField.focus();
@divdavem Collaborator

Note that this method is called on blur. Is it really a good idea to always move the focus back to the text field?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 23, 2014
  1. @smadapathi
This page is out of date. Refresh to see the latest.
View
71 src/aria/resources/handlers/LCRangeResourceHandler.js
@@ -59,56 +59,35 @@
* @param {aria.core.CfgBeans.Callback} callback Called when suggestions are ready
*/
getSuggestions : function (textEntry, callback) {
-
- if (typesUtil.isString(textEntry) && textEntry.length >= this.threshold) {
- textEntry = stringUtil.stripAccents(textEntry).toLowerCase();
-
- var codeSuggestions = [], labelSuggestions = [], nbSuggestions = this._suggestions.length, textEntryLength = textEntry.length;
- var results = {};
- var index, suggestion, isRangeValue = false;
- var patt = this.rangePattern;
- if (this.allowRangeValues && patt.test(textEntry)) {
- var firstLetter = textEntry.charAt(0);
- var rangeV = textEntry.substring(1).split("-");
- isRangeValue = true;
- } else {
- var rangeV = [];
- rangeV[0] = 1;
- rangeV[1] = 1;
- }
+ if (!typesUtil.isString(textEntry) || textEntry.length < this.threshold) {
+ this.$callback(callback, null);
+ return;
+ }
+ textEntry = stringUtil.stripAccents(textEntry).toLowerCase();
+ if (this.allowRangeValues && this.rangePattern.test(textEntry)) {
+ var firstLetter = textEntry.charAt(0);
+ var rangeV = textEntry.substring(1).split("-");
+ var results = {
+ suggestions : [],
+ multipleValues : true
+ };
for (var k = rangeV[0]; k <= rangeV[1]; k++) {
- textEntry = firstLetter ? firstLetter + k : textEntry;
- textEntryLength = textEntry.length;
- for (index = 0; index < nbSuggestions; index++) {
- suggestion = this._suggestions[index];
- if (suggestion.code === textEntry) {
- suggestion.original.exactMatch = !isRangeValue && true;
- codeSuggestions.unshift(suggestion.original);
- } else if (suggestion.code.substring(0, textEntryLength) === textEntry
- && !this.codeExactMatch) {
- codeSuggestions.push(suggestion.original);
- suggestion.original.exactMatch = false;
- } else {
- if (suggestion.label.substring(0, textEntryLength) === textEntry) {
- var exactMatch = suggestion.label === textEntry;
- exactMatch = !isRangeValue && exactMatch;
- suggestion.original.exactMatch = exactMatch;
- if (exactMatch) {
- labelSuggestions.unshift(suggestion.original);
- } else {
- labelSuggestions.push(suggestion.original);
- }
- }
- }
- }
+ var textEntry = firstLetter + k;
+ this.$LCResourcesHandler.getSuggestions.call(this, textEntry, {
+ fn : this.__appendSuggestions,
+ scope : this,
+ args : results
+ });
}
-
- var suggestions = codeSuggestions.concat(labelSuggestions);
- results.suggestions = suggestions;
- results.multipleValues = isRangeValue;
this.$callback(callback, results);
} else {
- this.$callback(callback, null);
+ this.$LCResourcesHandler.getSuggestions.call(this, textEntry, callback);
+ }
+ },
+
+ __appendSuggestions : function (suggestions, results) {
+ if (suggestions) {
+ results.suggestions = results.suggestions.concat(suggestions);
}
}
View
42 src/aria/widgets/controllers/MultiAutoCompleteController.js
@@ -25,7 +25,7 @@
Aria.classDefinition({
$classpath : "aria.widgets.controllers.MultiAutoCompleteController",
$extends : "aria.widgets.controllers.AutoCompleteController",
- $dependencies : ["aria.utils.Delegate", "aria.utils.Array", "aria.utils.Json"],
+ $dependencies : ["aria.utils.Delegate", "aria.utils.Array", "aria.utils.Json", "aria.utils.String"],
$onload : function () {
typeUtil = aria.utils.Type;
arrayUtil = aria.utils.Array;
@@ -85,14 +85,15 @@
*/
checkText : function (text, init) {
var dataModel = this._dataModel, controller = this, addedValue;
+ var trimText = aria.utils.String.trim(text);
if (text !== '' && text !== dataModel.text) {
- dataModel.text = text;
- this._resourcesHandler.getSuggestions(text, {
+ dataModel.text = trimText;
+ this._resourcesHandler.getSuggestions(trimText, {
fn : this._suggestionsCallback,
scope : this,
args : {
- nextValue : text,
+ nextValue : trimText,
triggerDropDown : false
}
}, controller.selectedSuggestionsLabelsArray);
@@ -100,8 +101,12 @@
}
var report = new aria.widgets.controllers.reports.DropDownControllerReport();
+ if (this.maxOptions && this.selectedSuggestions.length == this.maxOptions) {
+ trimText = "";
+ }
+
// an empty field is usually not considered as an error
- if (text === '') {
+ if (trimText === '') {
dataModel.value = null;
dataModel.text = '';
report.ok = true;
@@ -109,16 +114,14 @@
} else {
if (this.freeText) {
report.ok = true;
- if (this.editMode && text === this.editedSuggestion.label) {
+ if (this.editMode && trimText === this.editedSuggestion.label) {
addedValue = this.editedSuggestion;
dataModel.value = addedValue;
} else {
- addedValue = text;
+ addedValue = trimText;
}
this._suggestionToBeAdded = addedValue;
- if (this.selectedSuggestions.length > 0 && !init) {
- addedValue = this._checkValidSuggestion(addedValue);
- }
+ addedValue = this._checkValidSuggestion(addedValue);
} else {
if (!dataModel.value) {
report.ok = false;
@@ -188,9 +191,7 @@
if (this.editMode) {
this._suggestionToBeAdded = "";
}
- if (this.selectedSuggestions.length > 0 && !init) {
- addedValue = this._checkValidSuggestion(this._suggestionToBeAdded);
- }
+ addedValue = this._checkValidSuggestion(this._suggestionToBeAdded);
report.value = addedValue;
report.text = dataModel.text;
return report;
@@ -279,17 +280,12 @@
report.text = nextValue;
report.caretPosStart = args.caretPosStart;
report.caretPosEnd = args.caretPosEnd;
-
- if (matchValueIndex != -1) {
- dataModel.value = dataModel.listContent[matchValueIndex].value;
+ var freeText = this.freeText || hasSuggestions;
+ if (freeText && nextValue) {
+ // return the text from the autocomplete
+ dataModel.value = nextValue;
} else {
- var freeText = this.freeText || hasSuggestions;
- if (freeText && nextValue) {
- // return the text from the autocomplete
- dataModel.value = nextValue;
- } else {
- dataModel.value = null;
- }
+ dataModel.value = null;
}
report.value = dataModel.value;
View
144 src/aria/widgets/form/MultiAutoComplete.js
@@ -99,9 +99,22 @@ Aria.classDefinition({
if (element.className === "closeBtn") {
this._removeMultiselectValues(element, event);
}
+ this.__resizeInput();
this._textInputField.focus();
},
/**
+ * Private method to increase the textInput width on focus
+ * @private
+ */
+ __resizeInput : function () {
+ var skinObj = this._skinObj, frame = this._frame, obj = this._textInputField;
+ if (obj) {
+ var frameWidth = frame.innerWidth - skinObj.innerPaddingLeft - skinObj.innerPaddingRight, inputWidth = obj.offsetLeft;
+ obj.style.width = (frameWidth - inputWidth - 4) + "px";// tolerance of 1 character
+ }
+
+ },
+ /**
* Initialization method called by the delegate engine when the DOM is loaded
*/
initWidget : function () {
@@ -114,6 +127,7 @@ Aria.classDefinition({
},
/**
* Add the selected suggestion(s) to widget
+ * @protected
* @param {aria.widgets.form.MultiAutoComplete} ref
* @param {aria.widgets.controllers.reports.DropDownControllerReport} report
* @param {Object} arg Optional parameters
@@ -121,21 +135,24 @@ Aria.classDefinition({
_addMultiselectValues : function (report, arg) {
var controller = this.controller, suggestionToBeAdded = controller._suggestionToBeAdded;
- var typeUtil = aria.utils.Type;
-
var isValid;
+ var typeUtil = aria.utils.Type;
+ var domUtil = aria.utils.Dom;
if (controller.editMode) {
isValid = typeUtil.isString(suggestionToBeAdded);
} else {
isValid = typeUtil.isArray(suggestionToBeAdded) || typeUtil.isObject(suggestionToBeAdded);
}
- if (controller.freeText && suggestionToBeAdded && arg && arg.eventName == "blur") {
+ if (controller.freeText && suggestionToBeAdded) {
isValid = true;
}
+ if (controller.maxOptions && controller.selectedSuggestions.length == controller.maxOptions) {
+ this._textInputField.value = "";
+ }
if (isValid && suggestionToBeAdded && !this._dropdownPopup) {
- var suggestionsMarkup = "", domUtil = aria.utils.Dom;
- if (aria.utils.Type.isArray(suggestionToBeAdded)) {
+ var suggestionsMarkup = "";
+ if (typeUtil.isArray(suggestionToBeAdded)) {
var maxOptionsLength = (controller.maxOptions)
? aria.utils.Math.min((controller.maxOptions - controller.selectedSuggestions.length), suggestionToBeAdded.length)
: suggestionToBeAdded.length;
@@ -145,22 +162,21 @@ Aria.classDefinition({
} else {
var lessThanMaxOptions = controller.maxOptions
? controller.maxOptions > controller.selectedSuggestions.length
- : false;
+ : true;
if (lessThanMaxOptions) {
suggestionsMarkup = this._generateSuggestionMarkup(suggestionToBeAdded);
}
}
domUtil.insertAdjacentHTML(this._textInputField, "beforeBegin", suggestionsMarkup);
+ this.__createEllipsis(this._textInputField);
controller._suggestionToBeAdded = null;
this._textInputField.value = "";
- if (this._frame.getChild(0).lastChild !== this._textInputField) {
-
- domUtil.insertAdjacentHTML(this._frame.getChild(0).lastChild, "afterEnd", "<span></span>");
- domUtil.replaceDomElement(this._frame.getChild(0).lastChild, this._textInputField);
- }
+ this._makeInputFieldLastChild();
if (controller.editMode) {
controller.editMode = false;
}
+ this._textInputField.style.width = "0px";
+ this.__resizeInput();
}
},
@@ -189,42 +205,125 @@ Aria.classDefinition({
return suggestionMarkup;
},
/**
+ * Method to create ellipsis for an added Suggestion
+ * @param {HTMLElement} input textInputField
+ * @private
+ */
+ __createEllipsis : function (input) {
+ var ellipsisContainer = input.previousSibling, elementoffsetWidth = ellipsisContainer.offsetWidth, frameWidth = this._frame.innerWidth;
+ // 10 is to consider margin and padding
+ if (elementoffsetWidth >= (frameWidth - 10)) {
+ ellipsisContainer.firstChild.className += " ellipsisClass";
+ var elementWidth = frameWidth - ellipsisContainer.offsetLeft
+ - (ellipsisContainer.firstChild.offsetLeft + ellipsisContainer.lastChild.offsetWidth) * 2;
+ ellipsisContainer.firstChild.style.maxWidth = elementWidth + "px";
+ }
+
+ },
+ /**
* Handling double click event for editing suggestion
* @param {aria.utils.Event} event
+ * @protected
*/
_dom_ondblclick : function (event) {
if (event.type == "dblclick" && this.controller.freeText) {
var element = event.target;
- if (element.className == "xMultiAutoComplete_Option_Text") {
+ if (element.className.indexOf("xMultiAutoComplete_Option_Text") != -1) {
this._editMultiselectValue(element, event);
}
}
},
/**
+ * Handling blur event
+ * @param {aria.utils.Event} event
+ * @protected
+ */
+ _dom_onblur : function (event) {
+ var inputField = this.getTextInputField();
+ if (inputField.nextSibling != null && inputField.value === "") {
+ this._makeInputFieldLastChild();
+ }
+ this.$TextInput._dom_onblur.call(this, event);
+ },
+ /**
+ * Make the inputfield as last child of widget
+ * @protected
+ */
+ _makeInputFieldLastChild : function () {
+ var domUtil = aria.utils.Dom;
+ if (this._frame.getChild(0).lastChild !== this._textInputField) {
+ domUtil.insertAdjacentHTML(this._frame.getChild(0).lastChild, "afterEnd", "<span></span>");
+ domUtil.replaceDomElement(this._frame.getChild(0).lastChild, this._textInputField);
+ this._textInputField.style.width = "0px";
+ this.__resizeInput();
+ }
+ },
+ /**
+ * Handling keydow event for enter, backspace
+ * @param {aria.utils.Event} event
+ * @protected
+ */
+ _dom_onkeydown : function (event) {
+ var backspacePressed = (event.keyCode == event.KC_BACKSPACE);
+ var tabPressed = (event.keyCode == event.KC_TAB);
+ var inputField = this.getTextInputField();
+ var inputFieldValue = inputField.value;
+ var domUtil = aria.utils.Dom;
+ if (tabPressed && inputFieldValue !== "") {
+ event.preventDefault();
+ var report = this.controller.checkText(inputFieldValue, false);
+ this._reactToControllerReport(report);
+ this.setHelpText(false);
+ }
+ if (tabPressed && inputFieldValue === "" && inputField.nextSibling != null) {
+ event.preventDefault();
+ this._makeInputFieldLastChild();
+ this.setHelpText(false);
+ inputField.focus();
+ var newSuggestions = aria.utils.Json.copy(this.controller.selectedSuggestions);
+ this.setProperty("value", newSuggestions);
+
+ }
+ if (backspacePressed && inputFieldValue === "") {
+ var previousSiblingElement = domUtil.getPreviousSiblingElement(inputField);
+ if (previousSiblingElement) {
+ var previousSiblingLabel = previousSiblingElement.firstChild.innerText
+ || previousSiblingElement.firstChild.textContent;
+ domUtil.removeElement(previousSiblingElement);
+ this._removeValues(previousSiblingLabel);
+ }
+
+ }
+ this.$DropDownTextInput._dom_onkeydown.call(this, event);
+ },
+ /**
* To remove suggestion on click of close
+ * @protected
* @param {aria.utils.HTML} domElement
* @param {aria.widgets.form.MultiAutoComplete} ref
* @param {aria.utils.Event} event
*/
_removeMultiselectValues : function (domElement, event) {
- var parent = domElement.parentNode, domUtil = aria.utils.Dom;
- var controller = this.controller;
+ var parent = domElement.parentNode;
+ var domUtil = aria.utils.Dom;
var label = parent.firstChild.innerText || parent.firstChild.textContent;
- this._removeValues(label);
domUtil.removeElement(parent);
+ this._removeValues(label);
if (event.type == "click") {
this.getTextInputField().focus();
+
}
- var newSuggestions = aria.utils.Json.copy(controller.selectedSuggestions);
- this.setProperty("value", newSuggestions);
+
},
/**
* To edit suggestion on doubleclick
* @param {aria.utils.HTML} domElement
* @param {aria.utils.Event} event
+ * @protected
*/
_editMultiselectValue : function (domElement, event) {
- var domUtil = aria.utils.Dom, label, arg = {};
+ var label, arg = {};
+ var domUtil = aria.utils.Dom;
label = domElement.textContent || domElement.innerText;
domUtil.replaceDomElement(domElement.parentNode, this._textInputField);
this.controller.editMode = true;
@@ -232,6 +331,7 @@ Aria.classDefinition({
this._textInputField.focus();
// to select the edited text.
this._keepFocus = true;
+ // this._textInputField.style.width = "0px";
var report = this.controller.checkValue(label);
report.caretPosStart = 0;
report.caretPosEnd = label.length;
@@ -243,9 +343,11 @@ Aria.classDefinition({
/**
* To remove the label from widget
* @param {String} label
+ * @protected
*/
_removeValues : function (label) {
- var indexToRemove, arrayUtil = aria.utils.Array, controller = this.controller;
+ var indexToRemove, controller = this.controller;
+ var arrayUtil = aria.utils.Array;
arrayUtil.forEach(controller.selectedSuggestions, function (obj, index) {
var suggestionLabel = obj.label || obj;
if (suggestionLabel == label) {
@@ -255,6 +357,10 @@ Aria.classDefinition({
});
arrayUtil.removeAt(controller.selectedSuggestions, indexToRemove);
arrayUtil.remove(controller.selectedSuggestionsLabelsArray, label);
+ var newSuggestions = aria.utils.Json.copy(controller.selectedSuggestions);
+ this.setProperty("value", newSuggestions);
+ this._textInputField.style.width = "0px";
+ this.__resizeInput();
}
}
});
View
7 src/aria/widgets/form/MultiAutoCompleteStyle.tpl.css
@@ -60,6 +60,13 @@
display:inline-block;
cursor:pointer;
}
+ .xMultiAutoComplete_${skinClassName}_options span.ellipsisClass{
+ white-space:nowrap;
+ overflow:hidden;
+ text-overflow:ellipsis;
+ vertical-align:middle;
+ line-height:18px;
+ }
.xMultiAutoComplete_${skinClassName}_options a:hover{
background-position: -5px -5px;
}
View
1  test/aria/widgets/form/autocomplete/AutoCompleteTestSuite.js
@@ -57,5 +57,6 @@ Aria.classDefinition({
this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test6.MultiAutoRange");
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");
}
});
View
3  test/aria/widgets/form/autocomplete/multiautocomplete/template/MultiAutoTplScript.js
@@ -8,7 +8,8 @@ Aria.tplScriptDefinition({
$constructor : function () {
this._airLineHandler = new aria.resources.handlers.LCRangeResourceHandler({
- allowRangeValues : true
+ allowRangeValues : true,
+ labelMatchAtWordBoundaries : true
});
this._airLineHandler.setSuggestions([{
label : 'Air France',
View
18 test/aria/widgets/form/autocomplete/multiautocomplete/test1/MultiAutoAdd.js
@@ -67,6 +67,20 @@ Aria.classDefinition({
},
_selectVal2 : function () {
this.synEvent.type(this.getInputField("MultiAutoId"), "[down][enter]", {
+ fn : this._typeWithWordBoundary,
+ scope : this
+ });
+ },
+ _typeWithWordBoundary : function () {
+ this.synEvent.type(this.getInputField("MultiAutoId"), "sys", {
+ fn : this._wait,
+ scope : this,
+ args : this._selectVal3
+ });
+
+ },
+ _selectVal3 : function () {
+ this.synEvent.type(this.getInputField("MultiAutoId"), "[down][enter]", {
fn : this._checkSelected,
scope : this
});
@@ -74,8 +88,8 @@ Aria.classDefinition({
_checkSelected : function () {
var parentNode = this.getInputField("MultiAutoId").parentNode;
this.assertEquals(this.getInputField("MultiAutoId").value, "", "The Input Field should be empty.");
- this.assertEquals(parentNode.childNodes.length, 3, "The Wrong No. of elements are added.");
- var expectedVal = ["Air Canada", "Finnair"];
+ this.assertEquals(parentNode.childNodes.length, 4, "The Wrong No. of elements are added.");
+ var expectedVal = ["Air Canada", "Finnair", "Scandinavian Airlines System"];
for (var i = 0; i < parentNode.childNodes.length - 1; i++) {
var element = parentNode.childNodes[i].innerText || parentNode.childNodes[i].textContent;
this.assertEquals(element, expectedVal[i], "The Wrong values are added as for Autocomplete.");
View
2  test/aria/widgets/form/autocomplete/multiautocomplete/test5/MultiAutoEdit.js
@@ -108,7 +108,7 @@ Aria.classDefinition({
},
_checkValue : function () {
var parentNode = this.getInputField("MultiAutoId").parentNode;
- var expectedVal = ["Air Canada", "Air France"];
+ var expectedVal = ["Scandinavian Airlines System", "Air France" ];
for (var i = 0; i < parentNode.childNodes.length - 1; i++) {
var element = parentNode.childNodes[i].innerText || parentNode.childNodes[i].textContent;
this.assertEquals(element, expectedVal[i], "The Wrong values are edited for Autocomplete.");
View
2  test/aria/widgets/form/autocomplete/multiautocomplete/test6/MultiAutoRange.js
@@ -64,7 +64,7 @@ Aria.classDefinition({
},
_checkValues : function () {
var value = this.data.ac_airline_values;
- var rangeLabels = ['P4.redd', 'P3.red', 'P2.kon', 'P1.some'];
+ var rangeLabels = ['P1.some', 'P2.kon', 'P3.red', 'P4.redd'];
this.assertEquals(value.length, 4, "The Wrong range of elements are prefilled. Expected = 4, Prefilled = "
+ value.length);
for (var k = 0; k < value.length; k++) {
View
83 test/aria/widgets/form/autocomplete/multiautocomplete/test9/MultiAutoBackSpace.js
@@ -0,0 +1,83 @@
+/*
+ * 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.multiautocomplete.test9.MultiAutoBackSpace",
+ $extends : "aria.jsunit.TemplateTestCase",
+ $constructor : function () {
+ this.$TemplateTestCase.constructor.call(this);
+
+ this.data = {
+ ac_airline_values : []
+ };
+
+ // setTestEnv has to be invoked before runTemplateTest fires
+ this.setTestEnv({
+ template : "test.aria.widgets.form.autocomplete.multiautocomplete.template.MultiAutoTpl",
+ data : this.data
+ });
+
+ },
+ $prototype : {
+ /**
+ * 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
+ });
+ },
+
+ typeSomething : function (evt, callback) {
+ // give it the time to open a drop down
+ this.synEvent.type(this.getInputField("MultiAutoId"), "p1-5", {
+ fn : this._wait,
+ scope : this,
+ args : this._selectVal
+ });
+ },
+ _wait : function (evt, callback) {
+ aria.core.Timer.addCallback({
+ fn : callback,
+ scope : this,
+ delay : 800
+ });
+ },
+ _selectVal : function () {
+ this.synEvent.type(this.getInputField("MultiAutoId"), "[enter]", {
+ fn : this._pressBackSpace,
+ scope : this
+ });
+ },
+ _pressBackSpace : function () {
+ this.synEvent.type(this.getInputField("MultiAutoId"), "[backspace]", {
+ fn : this._checkValues,
+ scope : this
+ });
+ },
+ _checkValues : function () {
+ var value = this.data.ac_airline_values;
+ var rangeLabels = ['P1.some', 'P2.kon', 'P3.red'];
+ this.assertEquals(value.length, 3, "The Wrong range of elements are prefilled. Expected = 4, Prefilled = "
+ + value.length);
+ for (var k = 0; k < value.length; k++) {
+ this.assertEquals(value[k].label, rangeLabels[k], "The Wrong range of elements are prefilled. Expected = "
+ + value[k].label + " Prefilled = " + rangeLabels[k]);
+ }
+ this.notifyTemplateTestEnd();
+ }
+ }
+});
Something went wrong with that request. Please try again.