Home › Forums › Classic DFFS › Time tracker in DFFS
- This topic has 7 replies, 2 voices, and was last updated 6 years, 10 months ago by Alexander Bautz.
-
AuthorPosts
-
-
January 30, 2018 at 22:32 #19532
Hi Alex,
I am having issues with the time tracker you posted a while ago: time-tracker-in-a-dffs-enabled-list
I used this with my SP2010 site, which was recently upgraded to 2013. I now get a JS error when a new item is started. When hitting OK the start timer button is not showing.
I created a new list, and added the code itself, the button shows and starts the timer. I then added each new column one at a time, and figured out the error only occurs when the multiple lines of text column are added. I’ve tried plain text and enhanced rich text.
Hoping you can help me figure this one out.
Thank you
Attachments:
-
February 1, 2018 at 23:03 #19568
It’s hard to tell, but if you could attach the Custom JS code here I might be able to see what could be wrong.
Do you see any errors in the console (hit F12 > Console)?
Alexander
-
February 6, 2018 at 02:12 #19617
Sorry for the delay:
using the same code you provided in the topic
(function(){ var a = [], b = [], tt; a.push("<tr style='font-size:18px;color:green;'>"); a.push("<td colspan='2' style='padding:2px;'>"); a.push("<span id='elapsedTime'></span><span id='totalTime'></span>"); a.push("</td>"); a.push("</tr>"); $("table.ms-formtable").prepend(a.join("")); b.push("<span title='You can save and close the list item while the timer is running. It will keep tracking time until you edit the item and click \"Stop the timer\".'>"); b.push("<input style='background-color:#C2CF8A;color:#444;' type='button' id='dffsTimeTrackerStartBtn' value='Start the timer' onclick='startTicker()'>"); b.push("<input style='background-color:#D57C7C;color:#ffffff;display:none;' type='button' id='dffsTimeTrackerStopBtn' value='Stop the timer' onclick='stopTicker()'>"); b.push("<span> </span>"); b.push("</span>"); $("input[id$='_diidIOSaveItem']:last").before(b.join("")); tt = getFieldValue("TotalTimeString"); if(tt !== ""){ $("#elapsedTime").html("Total time: "+getFriendlyTime(Number(tt))); } })(); function startTicker(){ var a= getFieldValue("StartTimeString"); if(a === ""){ setFieldValue("StartTimeString",new Date().valueOf()); $("#dffsTimeTrackerStartBtn").hide(); $("#dffsTimeTrackerStopBtn").show(); $("#totalTime").html(""); } } function stopTicker(){ var a = getFieldValue("StartTimeString") , b = new Date().valueOf() , u = spjs.utility.userInfo(_spPageContextInfo.userId) , et = b-Number(a) , tt = Number(getFieldValue("TotalTimeString")) + et , log = getFieldValue("Log") , al = getFieldValue("Activity"); setFieldValue("TotalTimeString",Number(tt)); // Reset start time and log setFieldValue("StartTimeString",""); setFieldValue("Activity",""); if(a !== ""){ if(log !== ""){ log += "\n*******************\n"; } if(al !== ""){ al = "\n\nActivity log:\n"+al; } setFieldValue("Log",log+u.Title+"\nStart: "+new Date(Number(a)).toLocaleString(_spPageContextInfo.currentUICultureName)+"\nEnd: "+new Date().toLocaleString(_spPageContextInfo.currentUICultureName)+"\nElapsed time="+getFriendlyTime(et)+al); } $("#elapsedTime").html(""); $("#totalTime").html("Total time: "+getFriendlyTime(tt)); $("#dffsTimeTrackerStartBtn").show(); $("#dffsTimeTrackerStopBtn").hide(); } function getFriendlyTime(ms){ var h, m, s; h = Math.floor(ms / 3600000); m = Math.floor((ms % 3600000) / 60000); s = Math.floor((ms % 60000) / 1000); return (h<10?"0"+h:h)+":"+(m<10?"0"+m:m)+":"+(s<10?"0"+s:s); } if(getFieldValue("StartTimeString") !== ""){ $("#dffsTimeTrackerStartBtn").hide(); $("#dffsTimeTrackerStopBtn").show(); } setInterval(function(){ var a = getFieldValue("StartTimeString"), b = new Date().valueOf(), tt = Number(getFieldValue("TotalTimeString")); if(a !== ""){ $("#elapsedTime").html("Elapsed time: "+getFriendlyTime(b - Number(a))); if(tt !== ""){ $("#elapsedTime").append(" / Total time: "+getFriendlyTime(tt + (b - Number(a)))); } } },1000);
console message:
jquery.js:4 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check https://xhr.spec.whatwg.org/.When i delete any multi line text field i get no error.
Attachments:
-
February 8, 2018 at 19:49 #19670
From this error it looks like you it fails in this line:
$("table.ms-formtable").prepend(a.join(""));
This is a bit strange because this is the default formtable. Could you try hitting F12 > console and type this in the console:
$("table.ms-formtable").length;
It should ouptput “1” when you hit enter.
The console error is “by design” and doesn’t result in any actual error – is related to a synchronous ajax request. I’ll fix this in a future DFFS update to make it asynchronous.
Alexander
-
February 8, 2018 at 20:00 #19672
Hi Alexander,
Here is the console response
$(“table.ms-formtable”).length;
VM344:1 Uncaught TypeError: Cannot read property ‘length’ of null
at <anonymous>:1:24 -
February 8, 2018 at 20:20 #19678
OK, this is strange. Is this a normal SharePoint form, or has it been modified in SharePoint Designer?
Alexander
-
February 8, 2018 at 22:22 #19688
It is a normal SP 2013 custom list. The form is only customized with DFFS.
I even tried creating a brand new test list and get the same errors.
-
February 10, 2018 at 12:50 #19732
What kind of list template did you use? Is it possible for me to log in and look at it? – if so, you can email me the login details.
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.