Permalink
Browse files

fix #980 Correct MultiAutoComplete initialization when bound data is …

…not empty

When freeText option was set to false, items already present in the data model to which the value of the widget is bound were not taken into account.
This commit reverts a fix done for another bug within commit 41d50bf: when freeText is equal to false, type some text for which there is no suggestion. Then blur. Then click inside the field and type something for which suggestions are returned. Pressing ENTER would cause all items to be duplicated.
  • Loading branch information...
1 parent 102e294 commit 1dfbc1e91244014aafcd75df6f030bd1f18f97fb @flongo flongo committed Feb 20, 2014
@@ -62,11 +62,6 @@
* @type Object
*/
this.editedSuggestion;
- /**
- * Suggestion to be added to the widget
- * @type Object or Array
- */
- this._suggestionToBeAdded = null;
/**
* Check if value is range of suggestions
* @type Boolean
@@ -120,7 +115,7 @@
} else {
addedValue = trimText;
}
- this._suggestionToBeAdded = addedValue;
+ report.suggestionsToAdd = addedValue;
addedValue = this._checkValidSuggestion(addedValue);
} else {
if (!dataModel.value) {
@@ -154,7 +149,7 @@
dataModel.value = null;
report.ok = true;
reportVal = null;
- } else if (value && !typeUtil.isString(value) && dataModel.value !== null) {
+ } else if (value && !typeUtil.isString(value)) {
if (this._checkWithSuggestionBean(value, this._resourcesHandler.SUGGESTION_BEAN)) {
var text = this._getLabelFromSuggestion(value);
dataModel.text = text;
@@ -186,14 +181,14 @@
}
}
- // var addedValue = rangeMatch || reportVal;
- addedValue = this._suggestionToBeAdded = rangeMatch.length > 0 ? rangeMatch : reportVal;
+ var suggestionsToAdd = rangeMatch.length > 0 ? rangeMatch : reportVal;
if (this.editMode) {
- this._suggestionToBeAdded = "";
+ suggestionsToAdd = "";
}
- addedValue = this._checkValidSuggestion(this._suggestionToBeAdded);
+ addedValue = this._checkValidSuggestion(suggestionsToAdd);
report.value = addedValue;
report.text = dataModel.text;
+ report.suggestionsToAdd = suggestionsToAdd;
return report;
},
/**
@@ -133,7 +133,7 @@ Aria.classDefinition({
*/
_addMultiselectValues : function (report, arg) {
- var controller = this.controller, suggestionToBeAdded = controller._suggestionToBeAdded;
+ var controller = this.controller, suggestionToBeAdded = report.suggestionsToAdd;
var isValid;
var typeUtil = aria.utils.Type;
var domUtil = aria.utils.Dom;
@@ -168,7 +168,6 @@ Aria.classDefinition({
}
domUtil.insertAdjacentHTML(this._textInputField, "beforeBegin", suggestionsMarkup);
this.__createEllipsis(this._textInputField);
- controller._suggestionToBeAdded = null;
this._textInputField.value = "";
this._makeInputFieldLastChild();
if (controller.editMode) {
@@ -49,16 +49,8 @@ Aria.classDefinition({
this.addTests("test.aria.widgets.form.autocomplete.helptext.test2.AutoCompleteHelptextTestCase");
this.addTests("test.aria.widgets.form.autocomplete.autoedit.AutoEditInput");
this.addTests("test.aria.widgets.form.autocomplete.issue697.EscKeyTestCase");
- this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test1.MultiAutoAdd");
- this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test2.MultiAutoRemove");
- this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test3.MultiAutoDataCheck");
- this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test4.MultiAutoPrefill");
- this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test5.MultiAutoEdit");
- this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test6.MultiAutoRange1");
- this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test6.MultiAutoRange2");
- 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");
+
+ this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.MultiAutoCompleteTestSuite");
}
});
@@ -0,0 +1,136 @@
+/*
+ * 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.BaseMultiAutoCompleteTestCase",
+ $extends : "aria.jsunit.TemplateTestCase",
+ $dependencies : ["aria.utils.Type"],
+ $constructor : function () {
+ this.$TemplateTestCase.constructor.call(this);
+
+ this.data = this.data || {
+ ac_airline_values : [],
+ freeText : true
+ };
+ this.setTestEnv({
+ template : "test.aria.widgets.form.autocomplete.multiautocomplete.template.MultiAutoTpl",
+ data : this.data
+ });
+
+ },
+ $prototype : {
+
+ clickAndType : function (text, cb, delay) {
+ if (aria.utils.Type.isString(text)) {
+ text = [text];
+ }
+ this.synEvent.click(this._getField(), {
+ fn : this.type,
+ scope : this,
+ args : {
+ text : text,
+ cb : cb,
+ delay : delay || 800
+ }
+ });
+ },
+
+ type : function (evt, args) {
+ args = args || evt;
+ this.synEvent.type(this._getField(), args.text.shift(), {
+ fn : this.__wait,
+ scope : this,
+ args : args
+ });
+ },
+
+ __wait : function (evt, args) {
+ var cb;
+ if (args.text.length === 0) {
+ cb = args.cb;
+
+ } else {
+ cb = {
+ fn : this.type,
+ scope : this,
+ args : args
+ };
+ }
+ cb.delay = args.delay;
+ aria.core.Timer.addCallback(cb);
+ },
+
+ checkSelectedItems : function (count, labels) {
+ var container = this._getContainer();
+ var actualOptionCount = container.children.length - 1;
+ this.assertEquals(actualOptionCount, count, "The number of selected options should be " + count
+ + ". It is " + actualOptionCount + " instead.");
+
+ if (labels) {
+ var element, text;
+ for (var i = 0; i < labels.length; i++) {
+ element = container.childNodes[i];
+ text = element.innerText || element.textContent;
+ this.assertEquals(text, labels[i], "The Wrong values are added as for Autocomplete.");
+ }
+ }
+ },
+
+ checkDataModel : function (count, expectedValues) {
+ var data = this.data.ac_airline_values, message;
+ this.assertEquals(data.length, count, "The number of items in the data model is not correct.");
+ if (expectedValues) {
+ for (var j = 0; j < data.length; j++) {
+ var message = "Wrong value in position " + j + " of the data model.";
+ if (aria.utils.Type.isString(data[j])) {
+ this.assertEquals(data[j], expectedValues[j], message);
+ } else {
+ this.assertEquals(data[j].code, expectedValues[j].code, message);
+ this.assertEquals(data[j].label, expectedValues[j].label, message);
+ }
+ }
+ }
+ },
+
+ focusOut : function (cb) {
+ this.templateCtxt.$focus("justToFocusOut");
+ cb.delay = cb.delay || 10;
+ aria.core.Timer.addCallback(cb);
+ },
+
+ checkInputValue : function (value) {
+ var actualValue = this._getField().value;
+ this.assertEquals(actualValue, value, "Input field should have value " + value + ". It has " + actualValue
+ + " instead.");
+ },
+
+ removeByCrossClick : function (index, cb) {
+ this.synEvent.click(this._getSelectedItemElement(index).lastChild, cb);
+ },
+
+ _getField : function () {
+ return this.getInputField("MultiAutoId");
+ },
+
+ _getContainer : function () {
+ return this._getField().parentNode;
+ },
+
+ _getSelectedItemElement : function (index) {
+ return this._getContainer().childNodes[index];
+ }
+
+ }
+});
@@ -0,0 +1,34 @@
+/*
+ * 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.MultiAutoCompleteTestSuite",
+ $extends : "aria.jsunit.TestSuite",
+ $constructor : function () {
+ this.$TestSuite.constructor.call(this);
+
+ this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test1.MultiAutoAdd");
+ this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test2.MultiAutoRemove");
+ this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test3.MultiAutoDataCheck");
+ this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test4.MultiAutoPrefill");
+ this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test5.MultiAutoEdit");
+ this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test6.MultiAutoRange1");
+ this.addTests("test.aria.widgets.form.autocomplete.multiautocomplete.test6.MultiAutoRange2");
+ 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.multiautocomplete.duplicateValuesAfterError.DuplicateValuesAfterError");
+ }
+});
@@ -0,0 +1,66 @@
+/*
+ * 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.duplicateValuesAfterError.DuplicateValuesAfterError",
+ $extends : "test.aria.widgets.form.autocomplete.multiautocomplete.BaseMultiAutoCompleteTestCase",
+ $constructor : function () {
+
+ this.data = {
+ ac_airline_values : [{
+ label : 'Air France',
+ code : 'AF'
+
+ }, {
+ label : 'Air Canada',
+ code : 'AC'
+ }],
+ freeText : false
+ };
+ this.$BaseMultiAutoCompleteTestCase.constructor.call(this);
+
+ },
+ $prototype : {
+
+ runTemplateTest : function () {
+ this.checkSelectedItems(2, ["Air France", "Air Canada"]);
+
+ this.clickAndType("o", {
+ fn : this._afterWrongType,
+ scope : this
+ }, 100);
+ },
+
+ _afterWrongType : function () {
+ this.focusOut({
+ fn : this._afterFocusOut,
+ scope : this
+ });
+ },
+
+ _afterFocusOut : function () {
+ this.clickAndType(["[right][backspace]P1", "[enter]"], {
+ fn : this._afterSelectionWithEnter,
+ scope : this
+ }, 200);
+ },
+
+ _afterSelectionWithEnter : function () {
+ this.checkSelectedItems(3, ["Air France", "Air Canada", "P1.some"]);
+ this.end();
+ }
+
+ }
+});
@@ -33,8 +33,8 @@
width:400,
block:false,
labelWidth:180,
- maxOptions: 8,
- freeText:true,
+ maxOptions: data.maxOptions || 8,
+ freeText: (data.freeText !== false),
resourcesHandler: getAirLinesHandler(),
bind:{
"value" : {
@@ -44,6 +44,8 @@
},
spellCheck: false
}/}
+ <br />
+ <input {id "justToFocusOut"/}>
{/macro}
{/Template}
Oops, something went wrong.

0 comments on commit 1dfbc1e

Please sign in to comment.