[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1614
  • Last Modified:

formatString for DateField won´t work!

Hello!

I want to format a DateField, which get his data and save the data from/to MYSQL database.
But everytime i get en error:

TypeError: Error #1034: Type Coercion failed: cannot convert "0000-00-00" to Date.
      at kunden/eventListener()[/Users/marioboro/Documents/Flex Builder 3/Kundenverwaltung/src/kunden.mxml:99]
      at kunden/__detailsButton_click()[/Users/marioboro/Documents/Flex Builder 3/Kundenverwaltung/src/kunden.mxml:147]

Please can somebody tell me, what i´m doing wrong?

Thank´s!
Mario
<mx:DateField id="dw_datum" formatString="YYYY-MM-DD"/>

Open in new window

Bild-3.jpg
0
20one
Asked:
20one
  • 10
  • 9
1 Solution
 
Jones911Commented:
Your not sending a data back from mySQL.  Place a debug point in your event handler and inspect the resultEvent and see whats actually comming back from the backend.
0
 
20oneAuthor Commented:
Thank´s.
How i can do this?
0
 
Jones911Commented:
In flexbuilder in the first line of your result event handeler double click the numbers on the side.  This will put a small circle on the number.  Then run the project in debug mode.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
20oneAuthor Commented:
In Debug Mode it highlight 2 lines in the code:

58:   _kundenDetails.dw_datum.selectedDate = dgUserRequest.selectedItem.dw_datum;

99:  _kundenDetails.dw_datum.selectedDate = dgUserRequest.selectedItem.dw_datum;

0
 
Jones911Commented:
OK so I'll assume now that your getting dates from mySQL and populating a datagrid?

Do they appear correctly in the datagrid?
0
 
20oneAuthor Commented:
Do you remember my example?

I load some data from mysql in a datagrid - that works perfect. When i highlight a row and click the open popup button, it load´s more data that belongs to the user. "dw_datum" is not shown in the datagrid, later then in the popup also dw_datum is displayed.

I have attach 2 txt-files. kunden.mxml is the main app, kundenDetails.mxml is the popup.
You´ll find the DateField at line 304 in kundenDetails.mxml

Thank´s!
kunden.txt
kundenDetails.txt
0
 
Jones911Commented:
OK add a test colum tot the datagrid using dw_datum as the datafield and take a look see if the data is coming back from mysql correctly.
0
 
20oneAuthor Commented:
Yes, data is coming back to the datagrid. It looks: 0000-00-00
0
 
20oneAuthor Commented:
And so looks the PHP
if (isset($_POST["emailaddress"]) && is_numeric($_POST["userid"])) {
	//mysql_query("INSERT INTO users (emailaddress,username) VALUES('".$_POST["emailaddress"]."','".$_POST["username"]."')");
	mysql_query("UPDATE users SET emailaddress='".$_POST["emailaddress"]."', username='".$_POST["username"]."', usernachname='".$_POST["usernachname"]."', anrede='".$_POST["anrede"]."', plz='".$_POST["plz"]."', ort='".$_POST["ort"]."', strasse='".$_POST["strasse"]."', tel_privat='".$_POST["tel_privat"]."', gebdatum='".$_POST["gebdatum"]."', beruf='".$_POST["beruf"]."', sonstiges='".$_POST["sonstiges"]."', dw_datum='".$_POST["dw_datum"]."', dw_bedienung='".$_POST["dw_bedienung"]."', dw_wickler='".$_POST["dw_wickler"]."', dw_anordnung='".$_POST["dw_anordnung"]."', dw_einwirkzeit='".$_POST["dw_einwirkzeit"]."', dw_nachbehandlung='".$_POST["dw_nachbehandlung"]."', dw_preis='".$_POST["dw_preis"]."', dw_anmerkungen='".$_POST["dw_anmerkungen"]."', fa_datum='".$_POST["fa_datum"]."', fa_bedienung='".$_POST["fa_bedienung"]."', fa_rezeptur='".$_POST["fa_rezeptur"]."', fa_einwirkzeit='".$_POST["fa_einwirkzeit"]."', fa_preis='".$_POST["fa_preis"]."', fa_anmerkungen='".$_POST["fa_anmerkungen"]."', image_url='".$_POST["image_url"]."' WHERE userid=".$_POST["userid"]);
}
 
 
$Query = "SELECT * from users";
$Result = mysql_query( $Query );
 
$Return = "<users>";
 
while ( $User = mysql_fetch_object( $Result ) )
{
$Return .= "<user><userid>".$User->userid."</userid><anrede>".$User->anrede."</anrede><username>".$User->username."</username><usernachname>".$User->usernachname."</usernachname><emailaddress>".$User->emailaddress."</emailaddress><plz>".$User->plz."</plz><ort>".$User->ort."</ort><strasse>".$User->strasse."</strasse><tel_privat>".$User->tel_privat."</tel_privat><gebdatum>".$User->gebdatum."</gebdatum><beruf>".$User->beruf."</beruf><sonstiges>".$User->sonstiges."</sonstiges><dw_datum>".$User->dw_datum."</dw_datum><dw_bedienung>".$User->dw_bedienung."</dw_bedienung><dw_wickler>".$User->dw_wickler."</dw_wickler><dw_anordnung>".$User->dw_anordnung."</dw_anordnung><dw_einwirkzeit>".$User->dw_einwirkzeit."</dw_einwirkzeit><dw_nachbehandlung>".$User->dw_nachbehandlung."</dw_nachbehandlung><dw_preis>".$User->dw_preis."</dw_preis><dw_anmerkungen>".$User->dw_anmerkungen."</dw_anmerkungen><fa_datum>".$User->fa_datum."</fa_datum><fa_bedienung>".$User->fa_bedienung."</fa_bedienung><fa_rezeptur>".$User->fa_rezeptur."</fa_rezeptur><fa_einwirkzeit>".$User->fa_einwirkzeit."</fa_einwirkzeit><fa_preis>".$User->fa_preis."</fa_preis><fa_anmerkungen>".$User->fa_anmerkungen."</fa_anmerkungen><image_url>".$User->image_url."</image_url></user>";
}

Open in new window

0
 
Jones911Commented:
Well that's not a valid date so there is your error :)

Now if you want a default date allow the coulm to have nulls set all the values to null then in flex do a check if dw_datum == null then _kundenDetails.dw_datum.selectedDate = null or new date() or what ever you want as default.
0
 
20oneAuthor Commented:
Thank´s, but please can you show me the solution in my code. And have i to change anything in the MYSQL db?
0
 
Jones911Commented:
Line 99 ish change:  _kundenDetails.dw_datum.selectedDate = dgUserRequest.selectedItem.dw_datum;

if( dgUserRequest.selectedItem.dw_datum == null){
     _kundenDetails.dw_datum.selectedDate = new Date();
}else{
  _kundenDetails.dw_datum.selectedDate = null;
}

Yes dont store invalid dates in mySQL.  While technically its valid its just better to store null if there is no date.
0
 
20oneAuthor Commented:
Thank´s.
I have modified the code. The error is away, but i when i define a date in the datefield, it will not be saved in the database.

And in the database i have store it to NULL, or not?
0
 
Jones911Commented:
Only the default date is null.

The date will save back to the database just fine.
0
 
20oneAuthor Commented:
And what have i now to change in the MYSQL DB?
0
 
Jones911Commented:
Allow NULL for the date field in the database.

As for the 0000-00-00 entries I'll presume this is just in testing so u can wipe the data so

update     tableName
set           columnName = null;

Will work.

1.jpg
0
 
20oneAuthor Commented:
OK, thank´s. Now when the popup is loaded, in the datefield the today´s date is shown. But when i change it and click my save button, it will not be saved in the database. Only 0000-00-00 instead of NULL.
0
 
Jones911Commented:
OK open a new question on how to save the date correctly and post the save Actionscript method and the php code.
0
 
20oneAuthor Commented:
Thank´s!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now