flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pio...@apache.org
Subject git commit: [flex-asjs] [refs/heads/feature/FLEX-35328_simplify_mdl_drop_down_list] - FLEX-35328 - Add ability to programmatic selection in MDL DropDownList
Date Sat, 24 Jun 2017 14:25:01 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/feature/FLEX-35328_simplify_mdl_drop_down_list f74836d4f -> 4b6de1691


FLEX-35328 - Add ability to programmatic selection in MDL DropDownList


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/4b6de169
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/4b6de169
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/4b6de169

Branch: refs/heads/feature/FLEX-35328_simplify_mdl_drop_down_list
Commit: 4b6de1691e02e2226deb5af4b81909907fff8bc1
Parents: f74836d
Author: piotrz <piotrz@apache.org>
Authored: Sat Jun 24 16:24:56 2017 +0200
Committer: piotrz <piotrz@apache.org>
Committed: Sat Jun 24 16:24:56 2017 +0200

----------------------------------------------------------------------
 .../beads/controllers/DropDownListController.as | 12 +++--
 .../flex/mdl/beads/views/DropDownListView.as    | 47 +++++++++++++++++++-
 2 files changed, 53 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4b6de169/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/controllers/DropDownListController.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/controllers/DropDownListController.as
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/controllers/DropDownListController.as
index ed1a90c..149be7d 100644
--- a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/controllers/DropDownListController.as
+++ b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/controllers/DropDownListController.as
@@ -83,10 +83,14 @@ package org.apache.flex.mdl.beads.controllers
 		COMPILE::JS
         private function onSelectChanged(event:Event):void
         {
-			var eventTarget:Object = event.target;
-			
-			model.selectedIndex = eventTarget.selectedIndex;
-			model.selectedItem = model.dataProvider[model.selectedIndex];
+            var eventTarget:Object = event.target;
+			var selectedIndex:int = eventTarget.selectedIndex - 1;
+
+			if (model.selectedIndex != selectedIndex)
+            {
+                model.selectedIndex = selectedIndex;
+                model.selectedItem = model.dataProvider[selectedIndex];
+            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/4b6de169/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/DropDownListView.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/DropDownListView.as
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/DropDownListView.as
index e3c1658..cad3e0d 100644
--- a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/DropDownListView.as
+++ b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/views/DropDownListView.as
@@ -18,6 +18,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.mdl.beads.views
 {
+    import org.apache.flex.core.ISelectionModel;
     import org.apache.flex.core.IStrand;
     import org.apache.flex.html.Option;
     import org.apache.flex.html.Select;
@@ -27,8 +28,7 @@ package org.apache.flex.mdl.beads.views
 
     /**
      *  The DropDownListView class creates the visual elements of the org.apache.flex.mdl.DropDownList
-     *  component. The job of the view bead is to put together the parts of the DropDownList
such as the Label
-     *  control and material icon ARROW_DROP_DOWN to trigger the pop-up.
+     *  component. The job of the view bead is to put together the parts of the DropDownList
such as the Select and Label
      *
      *  @viewbead
      *  @langversion 3.0
@@ -79,9 +79,39 @@ package org.apache.flex.mdl.beads.views
             }
         }
 
+        override protected function dataProviderChangeHandler(event:Event):void
+        {
+            super.dataProviderChangeHandler(event);
+
+            COMPILE::JS
+            {
+                setProgrammaticallyChangedSelection();
+            }
+        }
+
+        override protected function itemsCreatedHandler(event:org.apache.flex.events.Event):void
+        {
+            super.itemsCreatedHandler(event);
+
+            COMPILE::JS
+            {
+                setProgrammaticallyChangedSelection();
+            }
+        }
+
+        private function selectionChangeHandler(event:Event):void
+        {
+            COMPILE::JS
+            {
+                setProgrammaticallyChangedSelection();
+            }
+        }
+
         override protected function handleInitComplete(event:Event):void
         {
             super.handleInitComplete(event);
+            
+            dataModel.addEventListener("selectedIndexChanged", selectionChangeHandler);
 
             COMPILE::JS
             {
@@ -98,5 +128,18 @@ package org.apache.flex.mdl.beads.views
             dropDownList.labelDisplay.htmlFor = name;
             dropDownList.dropDown.element.name = name;
         }
+
+        COMPILE::JS
+        private function setProgrammaticallyChangedSelection():void
+        {
+            var dropDownList:DropDownList = (_strand as DropDownList);
+            var selectedIndex:int = dropDownList.dropDown.element["selectedIndex"] - 1;
+            var model:ISelectionModel = dataModel as ISelectionModel;
+
+            if (model.selectedIndex > -1 && model.dataProvider && model.selectedIndex
!= selectedIndex)
+            {
+                dropDownList.dropDown.element["selectedIndex"] = model.selectedIndex + 1;
+            }
+        }
     }
 }
\ No newline at end of file


Mime
View raw message