2 Replies Latest reply on May 6, 2011 10:29 AM by Michelle5002

    Date divided into Date and Time in DataGrid But get errors on Time

    Michelle5002

      I have a Date field in a class and when I created a data Grid, I displayed the Date in one column and the Time for the same field in another column.  Displaying the info is fine.  When I edit the date column, it saves to date fine.  But when I edit the time column it gives me this error

       

      TypeError: Error #1034: Type Coercion failed: cannot convert "9:00 AM" to Date.

       

      So, its not saving it like I want.  Any Suggestions?

       

      Here is my code:

       

                  <mx:DataGridColumn headerText="Start Date" dataField="startDate" width="50"
                                     labelFunction="dateFormat" editorDataField="selectedDate">
                      <mx:itemEditor>
                          <fx:Component>
                              <mx:DateField editable="true"/>
                          </fx:Component>
                      </mx:itemEditor>
                  </mx:DataGridColumn>
                  <mx:DataGridColumn headerText="Start Time" dataField="startDate" width="50"
                                     labelFunction="timeFormat"/>

        • 1. Re: Date divided into Date and Time in DataGrid But get errors on Time
          Michelle5002 Level 1

          Not sure this is the best way but it worked. See Below for Code

          • 2. Re: Date divided into Date and Time in DataGrid But get errors on Time
            Michelle5002 Level 1

                        <mx:DataGridColumn id="startDateDC" headerText="Start Date" dataField="startDate" width="100"
                                           labelFunction="dateTimeFormat" editorDataField="value">
                            <mx:itemEditor>
                                <fx:Component>
                                    <mx:Canvas width="100%">
                                        <fx:Declarations>
                                            <mx:DateFormatter id="timeFormatter" formatString="L:NN A"/>
                                            <!-- Place non-visual elements (e.g., services, value objects) here -->
                                        </fx:Declarations>
                                        <s:HGroup width="100%">

             

                                            <fx:Script>
                                                <![CDATA[
                                                    protected function timeFormat(date:Date):String
                                                    {
                                                        return timeFormatter.format(date);
                                                    }

             

                                                    public function get value():Date
                                                    {
                                                        var date:Date = new Date(dateField.selectedDate.toDateString() + " " + timeField.text);
                                                        return date;
                                                    }
                                                   
                                                ]]>
                                            </fx:Script>
                                            <mx:DateField id="dateField"  editable="true" width="50%"
                                                          formatString="MM-DD-YYYY"
                                                           selectedDate="{outerDocument.nonAvailDg.selectedItem.startDate}"/>
                                            <mx:TextInput id = "timeField" editable="true" width="50%" 
                                                          data="{timeFormat(outerDocument.nonAvailDg.selectedItem.startDate)}"/>
                                        </s:HGroup>
                                    </mx:Canvas>
                                </fx:Component>
                            </mx:itemEditor>
                        </mx:DataGridColumn>