Navigation Menu

Skip to content

Commit

Permalink
fix ariatemplates#1087 HTML Select Widget updation of datamodel on ch…
Browse files Browse the repository at this point in the history
…ange
  • Loading branch information
smadapathi committed Apr 15, 2014
1 parent 6259bee commit 276f3f0
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/aria/html/Select.js
Expand Up @@ -32,6 +32,11 @@ Aria.classDefinition({
scope : this
});

this._chainListener(cfg.on, 'change', {
fn : this.__updateDataModel,
scope : this
});

this.$Element.constructor.call(this, cfg, context, line);
},
$prototype : {
Expand Down
1 change: 1 addition & 0 deletions test/aria/html/HTMLTestSuite.js
Expand Up @@ -28,6 +28,7 @@ Aria.classDefinition({
this.addTests("test.aria.html.radioButton.RadioButtonTest");
this.addTests("test.aria.html.select.SelectTest");
this.addTests("test.aria.html.select.bodycontent.BodyContentTestCase");
this.addTests("test.aria.html.select.onchange.DataModelOnChangeTestCase");
this.addTests("test.aria.html.DisabledTraitTest");
this.addTests("test.aria.html.radioButton.ieBug.RadioButtonTestCase");
this.addTests("test.aria.html.textarea.TextAreaTestSuite");
Expand Down
69 changes: 69 additions & 0 deletions test/aria/html/select/onchange/DataModelOnChangeTestCase.js
@@ -0,0 +1,69 @@
/*
* Copyright 2012 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.html.select.onchange.DataModelOnChangeTestCase",
$extends : "aria.jsunit.TemplateTestCase",
$dependencies : ["aria.utils.Dom", "aria.html.Select", "aria.utils.SynEvents"],
$constructor : function () {
this.$TemplateTestCase.constructor.call(this);

this.data = {
selectedOption : "EURO",
onChangeOption : ""
};
this.setTestEnv({
template : "test.aria.html.select.onchange.DataModelOnChangeTpl",
data : this.data
});

},
$prototype : {
runTemplateTest : function () {

var document = Aria.$window.document;
var selectWidgets = this.testDiv.getElementsByTagName("select");

// we know there's only one
var selectWidget = selectWidgets[0];
this.assertEquals(selectWidget.selectedIndex, 0, "The selected Index should be %2 but was %1 ");

// to be nullified in the callback of the click action
this.selectWidget = selectWidget;
this.selectWidget.focus();

this.synEvent.type(this.selectWidget, "[down][down][enter]", {
fn : function () {
this.templateCtxt.$focus("justToFocusOut");
this.waitFor({
condition : function () {
return this.data.onChangeOption !== "";
},
callback : this.afterChange
});

},
scope : this
});
},

afterChange : function () {
this.assertEquals(this.data.selectedOption, "POUND", "Selected Option should be %2 but was %1");
this.assertEquals(this.data.onChangeOption, "POUND", "Changed Option should be %2 but was %1");
this.end();
}

}
});
42 changes: 42 additions & 0 deletions test/aria/html/select/onchange/DataModelOnChangeTpl.tpl
@@ -0,0 +1,42 @@
/*
* Copyright 2012 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.html.select.onchange.DataModelOnChangeTpl",
$wlibs : {
html : "aria.html.HtmlLibrary"
},
$hasScript : true
}}

{macro main()}

{var myStringOptions = ["EURO","FRANC SUISSE","POUND"]/}

{@html:Select{
options : myStringOptions,
bind : {
value : {
inside : data,
to : "selectedOption"
}
},
on :{
change:myFunc
}
}/}
<input {id "justToFocusOut"/}>
{/macro}
{/Template}
23 changes: 23 additions & 0 deletions test/aria/html/select/onchange/DataModelOnChangeTplScript.js
@@ -0,0 +1,23 @@
/*
* Copyright 2012 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.html.select.onchange.DataModelOnChangeTplScript",
$prototype : {
myFunc : function () {
this.data.onChangeOption = this.data.selectedOption;
}
}
});

0 comments on commit 276f3f0

Please sign in to comment.