2 Replies Latest reply on Feb 26, 2008 11:48 AM by SiHoop

    Reset text field in mxml

    SiHoop Level 1
      How can I reset a text field that takes its value from a datagrid? My original text field (shown below) populates as required:
      <mx:TextInput text="{peopleDataGrid.selectedItem.first_name}" id="editFirstName" editable="true" styleName="panelCell" height="30" width="220"/>

      However, when I try to reset the text field by pressing a Cancel button (see below), it fails.

      <mx:Button click="editFirstName.text={peopleDataGrid.selectedItem.first_name} " label="Cancel" id="cancelEditButton" width="100"/>

      If I place the desired output in single quotes, it produces a literal text dump (see below)
      <mx:Button click="editFirstName.text='{peopleDataGrid.selectedItem.first_name}' " label="Cancel" id="cancelEditButton" width="100"/>
        • 1. Re: Reset text field in mxml
          Garyl Woolworth Level 1
          When setting a textfield back to a datagrids selectedItem you no longer need {}. Those are only to apply bindings for initial values. Here's an example of what I mean.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="popDP()">

          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;

          [Bindable] private var dp:ArrayCollection = new ArrayCollection();

          private function popDP():void {
          for(var i:Number = 0; i < 10; i++){
          dp.addItem({first_name:"first"+i, last_name:"last"+i});
          }
          }
          ]]>
          </mx:Script>

          <mx:Canvas width="100%" height="100%">
          <mx:Label x="10" y="10" text="FirstName:"/>
          <mx:TextInput x="10" y="27" id="editFirstName" text="{peopleDataGrid.selectedItem.first_name}"/>
          <mx:Button x="180" y="27" label="Save" click="dp.setItemAt({first_name:editFirstName.text, last_name:peopleDataGrid.selectedItem.last_name}, peopleDataGrid.selectedIndex)"/>
          <mx:Button x="249" y="27" label="Cancel" click="editFirstName.text=peopleDataGrid.selectedItem.first_name"/>

          <mx:DataGrid x="10" y="60" id="peopleDataGrid" dataProvider="{dp}">
          <mx:columns>
          <mx:DataGridColumn headerText="First Name" dataField="first_name"/>
          <mx:DataGridColumn headerText="Last Name" dataField="last_name"/>
          </mx:columns>
          </mx:DataGrid>
          </mx:Canvas>
          </mx:Application>
          • 2. Re: Reset text field in mxml
            SiHoop Level 1
            Thank you, that's perfect.