Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save a date field to Parse : invalid type for key, expected date, but got string

I have a very strange problem because some weeks ago, all worked well. But now, I cannot save a object containing a Date.

I use the Parse.com backend. I have a very simple class with just one field Date.

I do a very simple query :

var Day = Parse.Object.extend('Day');
var d = new Day();
var now = new Date();
d.set('dateField', now);
d.save();

I get an error :

invalid type for key dateField, expected date, but got string

if I try to do that :

d.set('dateField', {__type:"Date", iso:now.toISOString()}

I've got the same problem...

I hope somebody can help me, because, I have not any idea...

Thanks !

like image 387
EntrustName Avatar asked Jul 19 '14 16:07

EntrustName


1 Answers

Don't know what are you doing wrong there but this snippet works correctly for me. It is tested & working correctly.

Quick double check which you can make - COLUMN NAME of CLASS, NAME of CLASS, DATATYPE of the COlUMN, JS SDK version in SCRIPT TAG

  <script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.3.2.min.js"></script>

  <script type="text/javascript">
    Parse.initialize("APPID", "JS KEY");
    
    var TestObject = Parse.Object.extend("CLASSNAME");
	var currentDate = new Date();
    var testObject = new TestObject();
	testObject.set('datefield', currentDate);
      testObject.save(null, {
      success: function(object) {
        $(".success").show();
      },
      error: function(model, error) {
	    console.log('error - ', error);
        $(".error").show();
      }
    });
  </script>
like image 84
Vintesh Avatar answered Oct 15 '22 11:10

Vintesh