11 Replies Latest reply on Aug 13, 2007 6:58 AM by Handycam

    Numeric stepper control problem

    Handycam Level 1
      I have a drag-n-drop grid. Items are dropped in, and on the click of a button, totals are added up. If I use the default data, it works. However, my stepper is not getting the min/max values, which are set in my XML file. The stepper appears when clicked, but using values not in my file (system defaults?) and the new value is not recognized.

      The grid:

      quote:


      <mx:DataGrid id="choiceList" dataProvider="{_chosenItems}" width="100%" height="100%" wordWrap="true" variableRowHeight="true" editable="true" dropEnabled="true" dragEnabled="true" dragMoveEnabled="true" dragDrop="doDragDrop(event);">
      <mx:columns>
      <mx:DataGridColumn dataField="@qty" headerText="Quantity" width="70" itemEditor="myComponents.NSEditor" editorDataField="@qty"/>
      <mx:DataGridColumn dataField="@units" headerText="" width="40"/>
      <mx:DataGridColumn dataField="@ln2" headerText=""/>
      </mx:columns>
      </mx:DataGrid>



      The stepper, which is myComponents.NSEditor:
      quote:


      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="69" height="22">
      <mx:Script>
      <![CDATA[
      public function get newTotal ():uint{
      return step.value;
      }
      ]]>
      </mx:Script>
      <mx:NumericStepper id="step" minimum="{data.@minQ}" maximum="{data.@maxQ}" stepSize=".25" value="{data.@qty}" />
      </mx:VBox>



      And each item in that Datagrid follows the format:
      quote:


      <item ln1="Onions, chopped" ln2="chopped onions" sn="onions" minQ=".25" maxQ=".5" qty=".5" units="cups" />


        • 1. Re: Numeric stepper control problem
          ntsiii Level 3
          In your renderer, does the "data" object have any data in it? Use trace() to be sure.

          Tracy
          • 2. Re: Numeric stepper control problem
            Handycam Level 1
            No, it's null. I've used this setup before successfully, but not when the dataProvider was an XMLList (only ArrayCollections).

            Any thoughts on the correct syntax?

            The trace got me:

            null
            warning: unable to bind to property 'qty' on class 'XML' (class is not an IEventDispatcher)
            warning: unable to bind to property 'maxQ' on class 'XML' (class is not an IEventDispatcher)
            warning: unable to bind to property 'minQ' on class 'XML' (class is not an IEventDispatcher)

            • 3. Re: Numeric stepper control problem
              ntsiii Level 3
              The warnings are because "data" is an Object and you can't bind to properties of an Object. Cast data as XML an the warnings will go away:
              minimum="{XML(data).@minQ}"

              I advise overriding the set data() method. That way you can be sure your renderer is getting data passed in.

              Tracy
              • 4. Numeric stepper control problem
                Handycam Level 1
                OK, that did stop the error but the data is still null, and the stepper still does not work (incorrect min/max and reverting to 0)

                Again, I've got this in my datagrid:
                <mx:DataGridColumn dataField="@qty" headerText="Quantity" width="70" itemEditor="myComponents.List2Editor" editorDataField="newTotal"/>

                And this is the stepper, List2Editor:

                <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="69" height="22">
                <mx:Script>
                <![CDATA[
                public function get newTotal ():uint{
                return step.value;
                }
                ]]>
                </mx:Script>
                <mx:NumericStepper id="step" minimum="{XML(data).@minQ}" maximum="{XML(data).@minQ}" stepSize=".25" value="{XML(data).@qty}" />
                </mx:VBox>
                • 5. Re: Numeric stepper control problem
                  ntsiii Level 3
                  Override the set data() method. That way you trace the argument using toXMLString() and can be sure your renderer is getting data passed in.
                  Tracy
                  • 6. Re: Numeric stepper control problem
                    Handycam Level 1
                    How do I override the setdata() method? Where is this method being called?
                    • 7. Re: Numeric stepper control problem
                      ntsiii Level 3
                      I have several itemRenderer examples on cflex.net. Look at the checkbox one.

                      The set data() method gets called by the list-based control when it is rendering an itemRenderer, which it does when you scroll or when the dataProvider changes.

                      Also, search the livedocs for: override set data
                      Tracy
                      • 8. Re: Numeric stepper control problem
                        Handycam Level 1
                        OK, I looked at it. The part I don't understand is
                        quote:


                        private var _xmlItem:XML; //holds the current item xml node

                        //Sets the state of the checkbox to the value of the selected attribute
                        //If there is no selected attribute, create on and set it to false
                        override public function set data(oItem:Object):void
                        {
                        _xmlItem = XML(oItem);
                        }



                        And how that relates to the stepper's attrributes:
                        quote:


                        <mx:NumericStepper id="step" minimum="{XML(data).@minQ}" maximum="{XML(data).@minQ}" stepSize=".25" value="{XML(data).@qty}" />



                        • 9. Re: Numeric stepper control problem
                          Handycam Level 1
                          OK, I tried it like this (hard-coding the min and max), but the compiler fails with an error:

                          Line: 24
                          Error: Data binding will not be able to detect assignments to "data".

                          quote:


                          <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="69" height="22">
                          <mx:Script>
                          <![CDATA[
                          private var _xmlItem:XML; //holds the current item xml node

                          override public function set data(oItem:Object):void
                          {
                          _xmlItem = XML(oItem);
                          }

                          override public function get data():Object
                          {
                          return step.value;
                          }

                          private function onChange():void
                          {
                          _xmlItem.@qty = Number(step.value);
                          }
                          ]]>

                          </mx:Script>
                          <mx:NumericStepper id="step" minimum="0" maximum="1" stepSize=".25" value="{XML(data).@qty}" />
                          </mx:VBox>



                          • 10. Re: Numeric stepper control problem
                            ntsiii Level 3
                            Because "data" is local to the set data method. That is the reason for the instance variable _xmlItem.

                            Bind to that. It is already XML, so the cast/conversion is not necessary.
                            value="{_xmlItem.@qty}"

                            also, put a trace in the set data method:
                            override public function set data(oItem:Object):void
                            {
                            _xmlItem = XML(oItem);
                            trace(_xmlItem.toXMLString())

                            You should see recognizable xml item nodes.

                            Tracy
                            • 11. Re: Numeric stepper control problem
                              Handycam Level 1
                              You know, after agonizing over this for weeks it turns out my original approach was fine -- there was actually just one small error in it, which technically is not even an error:

                              public function get newTotal ():uint{
                              return step.value;
                              }

                              I had used this function last time WITH WHOLE NUMBERS. So that's why it kept returning "0" it was rounding.

                              changed it to:

                              public function get newTotal ():Number{
                              return step.value;
                              }

                              It works fine now! For completeness sake, here's the stepper:

                              <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="69" height="22">
                              <mx:Script>
                              <![CDATA[
                              public function get newTotal ():Number{
                              return step.value;
                              }
                              ]]>
                              </mx:Script>
                              <mx:NumericStepper id="step" minimum=".25" maximum="1" stepSize=".25" value="{data.@qty}" />
                              </mx:VBox>

                              and the corresponding data grid column:

                              <mx:DataGridColumn dataField="@qty" headerText="Quantity" width="70" itemEditor="myComponents.NSEditor_max3" editorDataField="newTotal"/>

                              No elaborate set data overrides or anything needed. Simple is always better.