Question

My goal is to pull a value on the EditForm from a Date field. I want to take the 'due date' field, do a "get date", and subtract the difference between that date and today to get a "days left" number. I don't think the last part will be difficult since I'm fairly familiar with javascript, but the getFieldValue with the four parameters method isn't returning anything. Is there a better method to choose?

Well, I tried....

var myDate = //
alert(myDate)

......but that won't work because it's not a single line of text.

I tried:

var theDate = getFieldValue('Due Date','','; ','');
alert(theDate);
Was it helpful?

Solution

I'm not sure that I understand your difficulty. I used your jQuery above in the following way:

<input type="text" 
       value="2/21/2014" 
       maxlength="45" 
       id="DueDate_42f25f08-a9dc-4559-aded-a2e2b9ec5e13_$DateTimeFieldDate" 
       title="Due Date" 
       class="ms-input" autopostback="0">

//I typed this into the console. I use Moment.js for most of my date-time work.
var myDate = new Date( $("input[title='Due Date']").val());
var timeLeft = moment(myDate).fromNow();
console.log("This item is due " + timeLeft + ".");

And got this:

enter image description here

Injected into my page via

var myDate = new Date( $("input[title='Due Date']").val());
var timeLeft = moment(myDate).fromNow();
$("#time-left").text("This item is due " + timeLeft + ".");

enter image description here

So your code should work just fine!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top