This project has moved and is read-only. For the latest updates, please go here.

ReadOnly Date Field Object Error

Apr 16, 2012 at 6:44 PM
Edited Apr 16, 2012 at 6:49 PM

First off, this code is great! Well done on something that is shocking that MS didn't think of doing in 2007.

So far everything works great on the EditForm.aspx however I am getting an Object Error when trying to make a date field readonly.

The Date Field (called 'Expiry Date') has a pre-populated value in it already - i just want to make that field readonly while others fields can still be editted.  I have the following code in my SPUtility-example script

SPUtility.GetSPField('Expiry Date').MakeReadOnly();

Any thoughts on why I am getting this Object Error?

Apr 16, 2012 at 6:58 PM

Sorry to add to this, I am using IE8 and SP2007 is that helps.  Saw another post on Object Error - the difference here aside from it being a date value is that I am not setting a value in the field.  I removed the above line from the script and all other Readonly commands priot and below it worked fine which is why I am guessing the culprit is the date value.

Apr 17, 2012 at 2:18 AM

Sorry about that! I'll take a look. Are you using the latest version of SPUtility? Also, can you try adding the following right before your first SPUtility line to hopefully get a better error message:

SPUtility.Debug(true);
Usually the object error happens because SPUtility can't find the field... 

Apr 17, 2012 at 2:34 AM
Hi Kit! That was it... Put the code in as you instructed and it works like a charm!

Thanks!

From: "KitMenke" <notifications@codeplex.com>
Date: 16 Apr 2012 18:18:24 -0700
To: <anilsamuel@sympatico.ca>
ReplyTo: SPUtility@discussions.codeplex.com
Subject: Re: ReadOnly Date Field Object Error [SPUtility:352466]

From: KitMenke

Sorry about that! I'll take a look. Are you using the latest version of SPUtility? Also, can you try adding the following right before your first SPUtility line to hopefully get a better error message:

SPUtility.Debug(true);
Usually the object error happens because SPUtility can't find the field...

Apr 17, 2012 at 2:24 PM

Setting Debug to true made the error go away??? That is a new one. :)

Apr 20, 2012 at 7:24 PM

Hi Kit,

Perhaps I spoke too soon.  When I added the Debug function like below it worked out fine but now I am noticing that when you go into the EditForm.aspx, I am getting the Object Error again.  But... when I hit close and then go back into the same record, it works out fine.  Some records in the list work fine the first time around.

try {
   SPUtility.Debug(true);
   SPUtility.GetSPField('Customer Name').MakeReadOnly();
SPUtility.GetSPField('Contract Date').MakeReadOnly(); } catch(ex)

Not sure why it's a hit or miss sometimes, any thoughts?

Apr 23, 2012 at 2:23 AM

Hm.. what type of list is this? Is it an external list?

Apr 23, 2012 at 2:37 AM
Hi Kit,

It's just a standard list on SharePoint - it seems the [object error] happens when it's trying to make the date field readonly since everything before it is changed to readonly.

I'm putting the script in a CEWP that resides above the list, does it maybe need to be below it after it loads?
From: "KitMenke" <notifications@codeplex.com>
Date: 22 Apr 2012 18:23:34 -0700
To: <anilsamuel@sympatico.ca>
ReplyTo: SPUtility@discussions.codeplex.com
Subject: Re: ReadOnly Date Field Object Error [SPUtility:352466]

From: KitMenke

Hm.. what type of list is this? Is it an external list?

Apr 23, 2012 at 4:15 AM

I think this might be a similar issue to: http://sputility.codeplex.com/discussions/304586. It was an issue with making empty date fields read only. Is the date field populated or empty?

Can you try this version of SPUtility.js? http://sputility.codeplex.com/SourceControl/changeset/view/c013f52e01d4#SPUtility.js

If it works, I will promote that as a bug fix version.

Apr 23, 2012 at 4:18 AM
Most of them are all pre-populated however some could possibly be empty. The object error I'm getting are for items that already have a value in the date field.

From: "KitMenke" <notifications@codeplex.com>
Date: 22 Apr 2012 20:15:54 -0700
To: <anilsamuel@sympatico.ca>
ReplyTo: SPUtility@discussions.codeplex.com
Subject: Re: ReadOnly Date Field Object Error [SPUtility:352466]

From: KitMenke

I think this might be a similar issue to: http://sputility.codeplex.com/discussions/304586. It was an issue with making empty date fields read only. Is the date field populated or empty?

Can you try this version of SPUtility.js? http://sputility.codeplex.com/SourceControl/changeset/view/c013f52e01d4#SPUtility.js

If it works, I will promote that as a bug fix version.

Apr 23, 2012 at 4:38 PM
Edited Apr 23, 2012 at 4:38 PM

Ok I just tested this again using Prototype 1.7, SPUtility.js 0.8, SP 2007, IE 8. I have the following script included in a CEWP on EditForm.aspx:

<script type="text/javascript" src="/sites/Kit/Kits Site Documents/prototype.js"></script>
<script type="text/javascript" src="/sites/Kit/Kits Site Documents/SPUtility.js"></script>
<script type="text/javascript" src="/sites/Kit/Kits Site Documents/SPUtility-example.js"></script>

The following is in SPUtility-example.js:

/* SPUtility.js example script */

// run after the page has loaded
Event.observe(window,'load',function(){
	try {
		// TODO: Put your code here...
		SPUtility.GetSPField('Title').MakeReadOnly();
		SPUtility.GetSPField('Date Field').MakeReadOnly();
		SPUtility.GetSPField('Date Time Field').MakeReadOnly();
	} catch (ex) {
		alert(ex.toString());
	}
});

I was able to get it to break when the Date field is EMPTY... but not when it has a value.

Do you have any other scripts being included on the page? jQuery perhaps?

Can you try this version and let me know if it works? http://sputility.codeplex.com/SourceControl/changeset/view/c013f52e01d4#SPUtility.js

Apr 23, 2012 at 8:25 PM

Hey Kit,

I used your new SPUtility.js file and so far so good.  Tried it with two users on two seperate items on list; one with a pre-populated date and one without and got no errors.

I am not using Jquery anywhere else on the page. I'll try it again later today on another machine but thank you for all your help on this!  This is such a great script!