Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix #223 multiselect widget changes for maxoptions #271

Closed
wants to merge 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 18, 2012
  1. @smadapathi

    fix #223 multiselect widget changes for maxoptions

    smadapathi authored unknown committed
This page is out of date. Refresh to see the latest.
View
20 src/aria/widgets/controllers/MultiSelectController.js
@@ -44,6 +44,13 @@ Aria.classDefinition({
this._dataModel.selectedValues = [];
/**
+ * Maximum no. of options to be selected from multiselect
+ * @protected
+ * @type Integer
+ */
+ this._maxOptions = null;
+
+ /**
* Map between values and text display. The goal is too return the same object for the same text in the input,
* for the case where the user check and uncheck an element in the multiselect dropdown
* @protected
@@ -71,6 +78,14 @@ Aria.classDefinition({
},
/**
+ * Set the configured maxOptions
+ * @param {Integer} maxOptions Used to select max no. of options from Multiselect
+ */
+ setMaxOptions : function (maxOptions) {
+ this._maxOptions = maxOptions;
+ },
+
+ /**
* Set the display mode for the field
* @param {String} separator Used to seperate items in the TextInput part of the multi-select
*/
@@ -156,7 +171,7 @@ Aria.classDefinition({
var inSplit = textFieldValue.split(this._separator);
if (inSplit) {
- for (var i = 0, inSplitLen = inSplit.length; i < inSplitLen; i++) {
+ for (var i = 0, inSplitLen = aria.utils.Math.min(inSplit.length, this._maxOptions); i < inSplitLen; i++) {
for (var j = 0, optionsLen = options.length; j < optionsLen; j++) {
var key = aria.utils.String.trim(inSplit[i]);
options[j].label = options[j].label + "";
@@ -165,7 +180,8 @@ Aria.classDefinition({
if ((options[j].label.toLowerCase() == key.toLowerCase() || options[j].value.toLowerCase() == key.toLowerCase())) {
if ((options[j].label.toLowerCase() == key.toLowerCase() || options[j].value.toLowerCase() == key.toLowerCase())
- && !aria.utils.Array.contains(selectedOptions, options[j].value) && !options[j].disabled) {
+ && !aria.utils.Array.contains(selectedOptions, options[j].value)
+ && !options[j].disabled) {
selectedOptions.push(options[j].value);
}
}
View
1  src/aria/widgets/form/MultiSelect.js
@@ -39,6 +39,7 @@ Aria.classDefinition({
// set control options
controller.setListOptions(cfg.items);
controller.setSeparator(cfg.fieldSeparator);
+ controller.setMaxOptions(cfg.maxOptions);
controller.setFieldDisplay(cfg.fieldDisplay);
controller.setValueDisplay(cfg.valueDisplay);
controller.checkError();
View
1  test/aria/widgets/WidgetsTestSuite.js
@@ -40,5 +40,6 @@ Aria.classDefinition({
this.addTests("test.aria.widgets.form.SelectTest");
this.addTests("test.aria.widgets.form.TextareaTest");
this.addTests("test.aria.widgets.form.TextInputTest");
+ this.addTests("test.aria.widgets.form.multiselect.issue223.MultiSelect");
}
});
View
39 test/aria/widgets/form/multiselect/issue223/MultiSelect.js
@@ -0,0 +1,39 @@
+Aria.classDefinition({
+ $classpath : 'test.aria.widgets.form.multiselect.issue223.MultiSelect',
+ $extends : 'aria.jsunit.TemplateTestCase',
+ $constructor : function () {
+ this.$TemplateTestCase.constructor.call(this);
+ },
+ $prototype : {
+
+ /**
+ * This method is always the first entry point to a template test Start the test by opening the MultiSelect
+ * popup.
+ */
+ runTemplateTest : function () {
+ this.assertTrue(this.getInputField("ms1").value === "");
+ this.getInputField("ms1").focus();
+ this.synEvent.type(this.getInputField("ms1"), "AF,AC,DL,AY", {
+ fn : this._afterTyping,
+ scope : this
+ });
+
+ },
+
+ _afterTyping: function(){
+ this.assertTrue(this.getInputField("ms1").value === "AF,AC,DL,AY");
+ aria.core.Timer.addCallback({
+ fn : this.finishTest,
+ scope : this,
+ delay : 100
+ });
+
+ },
+
+ finishTest : function () {
+ this.getInputField("myTextField").focus();
+ this.assertTrue(this.getInputField("ms1").value === "AF,AC,DL");
+ this.end();
+ }
+ }
+});
View
46 test/aria/widgets/form/multiselect/issue223/MultiSelectTpl.tpl
@@ -0,0 +1,46 @@
+{Template {
+ $classpath:'test.aria.widgets.form.multiselect.issue223.MultiSelectTpl',
+ $hasScript:false
+}}
+
+ {var content = {value : [""]}/}
+
+ {macro main()}
+ <h1>This test needs focus</h1>
+ {var testItems = [
+ {value:'AF', label:'AF', disabled:false},
+ {value:'AC', label:'AC', disabled:false},
+ {value:'NZ', label:'NZ', disabled:false},
+ {value:'DL', label:'DL', disabled:false},
+ {value:'AY', label:'AY', disabled:false},
+ {value:'IB', label:'IB', disabled:true},
+ {value:'LH', label:'LH', disabled:false},
+ {value:'MX', label:'MX', disabled:false},
+ {value:'QF', label:'QF', disabled:false}
+ ]/}
+ {@aria:MultiSelect {
+ activateSort: true,
+ label: "My Multi-select:",
+ labelWidth:150,
+ width:400,
+ fieldDisplay: "label",
+ id:"ms1",
+ fieldSeparator:',',
+ valueOrderedByClick: true,
+ maxOptions:3,
+ items:testItems,
+ bind:{
+ value : {
+ to : 'value',
+ inside : content
+ }
+ }
+ }/}
+
+ {@aria:TextField {
+ id : "myTextField",
+ margins : "10 20 10 10"
+ } /}
+ {/macro}
+
+{/Template}
Something went wrong with that request. Please try again.