Dear All
I need assistance on setting time limit on fields so the question skips automatically once the time limit per question has expired. For further clarity, I would like to set time limits on particular fields/variables e.g. set a limit of 4 minutes per question and if 4 minutes has expired without any entry in the field, the CAPI will automatically skip to the next question.
Any assistance on how to go about this would be much appreciated
Automatic skip after time limit on field
-
- Posts: 1882
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Automatic skip after time limit on field
There is no ability to set a timer using CSPro to do what you are describing. It is something that we could consider in the future, but I'd like to understand the use case for this. What is the motivation to have the data collection tool automatically skip to the next question?
Re: Automatic skip after time limit on field
Thank you Gregory for the response.
We are undertaking an education survey on school children literacy and numeracy. The protocol on the section on numeracy and literacy requires that each student have 4 minutes to answer every question. If the 4 minutes expires then their chance to answer that question expires hence they move on to answer the next question. This is to ensure that every student have equal chance and opportunity in answering a question (avoid bias). The assumption is that if a student is giving more time than another, it influences the outcome of the response hence equal opportunity needs to be given to all per question for all questions in that section.
We are undertaking an education survey on school children literacy and numeracy. The protocol on the section on numeracy and literacy requires that each student have 4 minutes to answer every question. If the 4 minutes expires then their chance to answer that question expires hence they move on to answer the next question. This is to ensure that every student have equal chance and opportunity in answering a question (avoid bias). The assumption is that if a student is giving more time than another, it influences the outcome of the response hence equal opportunity needs to be given to all per question for all questions in that section.
Re: Automatic skip after time limit on field
I thought It was possible using JS in CAPI webview part... and the new UI.postWebMessage (https://www.csprousers.org/help/CSPro/C ... ssage.html)
a) Should be possible to post a message with dictionary symbol name you want to "skip to" for triggering a JS timer in the CAPI webview. This message should be posted in the preproc of the Item.
b) You should use CSProActionInvoker.getWindowForEventListener in the CAPI's Webview to listen and activate the JS timer once the message is received;
c) Once the specified time is elapsed, you should call a CSPro user defined function in JS to skip to the specified item that the symbol name has been transmitted via the webmessage... But, because most CSPro dictionary functions don't support symbol name that are unknow until the runtime. So, I don't know if there are some workaround for skipping to a symbol name that are unknow until the runtime...
Aaron mentioned " directly call JavaScript from CSPro will likely be a feature in CSPro 8.1" (viewtopic.php?p=18011#p18011) . If implemented, it will be very simple to implement such tasks even without a native CSPro logic function.
Best,
a) Should be possible to post a message with dictionary symbol name you want to "skip to" for triggering a JS timer in the CAPI webview. This message should be posted in the preproc of the Item.
b) You should use CSProActionInvoker.getWindowForEventListener in the CAPI's Webview to listen and activate the JS timer once the message is received;
c) Once the specified time is elapsed, you should call a CSPro user defined function in JS to skip to the specified item that the symbol name has been transmitted via the webmessage... But, because most CSPro dictionary functions don't support symbol name that are unknow until the runtime. So, I don't know if there are some workaround for skipping to a symbol name that are unknow until the runtime...
Aaron mentioned " directly call JavaScript from CSPro will likely be a feature in CSPro 8.1" (viewtopic.php?p=18011#p18011) . If implemented, it will be very simple to implement such tasks even without a native CSPro logic function.
Best,
Last edited by htuser on January 28th, 2025, 7:46 am, edited 1 time in total.
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Automatic skip after time limit on field
Thank you @htuser for your response. I will look into it
Re: Automatic skip after time limit on field
Maybe, I'll try to share a demo implementing what I shared in my previous post.
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Automatic skip after time limit on field
Thank you once again @htuser. I will be grateful if you share a demo.
-
- Posts: 1882
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Automatic skip after time limit on field
Ah, @htuser's mention of JavaScript makes me change my answer. This is possible in CSPro 8.0. See attached for an example, where a question is skipped if the user doesn't enter a value within five seconds.
In CSPro, I added a function that will skip to a particular field:
In CSPro, I added a function that will skip to a particular field:
function SkipToField(string fieldName)
skip to @fieldName;
end;
And then the trickier part is the JavaScript. I set a timer that, when complete, uses the Action Invoker to call into CSPro logic to execute that SkipToField function. I added this as the HTML question text for the field:skip to @fieldName;
end;
<p>Skipping to FIELD_2 in <span id="seconds">...</span> seconds.</p>
<script src="/action-invoker.js"></script>
<script>
const secondsInterval = 1;
let secondsRemaining = 5;
const secondsSpan = document.getElementById("seconds");
secondsSpan.textContent = secondsRemaining;
const timerId = setInterval(runTimer, secondsInterval * 1000);
function runTimer() {
secondsRemaining -= secondsInterval;
secondsSpan.textContent = secondsRemaining;
if( secondsRemaining <= 0 ) {
clearInterval(timerId);
const CS = new CSProActionInvoker();
CS.Logic.invokeAsync({
function: "SkipToField",
arguments: {
fieldName: "FIELD_2"
}
});
}
}
</script>
This is definitely for advanced users, but it is impossible.<script src="/action-invoker.js"></script>
<script>
const secondsInterval = 1;
let secondsRemaining = 5;
const secondsSpan = document.getElementById("seconds");
secondsSpan.textContent = secondsRemaining;
const timerId = setInterval(runTimer, secondsInterval * 1000);
function runTimer() {
secondsRemaining -= secondsInterval;
secondsSpan.textContent = secondsRemaining;
if( secondsRemaining <= 0 ) {
clearInterval(timerId);
const CS = new CSProActionInvoker();
CS.Logic.invokeAsync({
function: "SkipToField",
arguments: {
fieldName: "FIELD_2"
}
});
}
}
</script>
- Attachments
-
- timed-question.7z
- (2.33 KiB) Downloaded 3696 times
Re: Automatic skip after time limit on field
Thanks @Greg for sharing. I'm very happy to see that the CSPro Development is still ongoing and I'm waiting for testing CSPro .8.1 (Eventually CAWI)...I was implementing a demo with approach I described in my previous post.
I discovered that the CAPI text Webview is not available to CSPro logic when posting a message, so CS.UI.enumerateWebViews() can't detect CAPI's webviewId.
I was trying some workaround by coding JS Action invoker in CAPI text webview and transfer it to CSPro logic using CS.Clipboard.putText...
Hopefully, you are coming with a more direct way! But, activate the timer with a message is a very good approach! And think it's also possible to share data between CSPro and JS using the CS.Clipboard.putText.
Thanks again to the CSPro Developer Team!
Best
I discovered that the CAPI text Webview is not available to CSPro logic when posting a message, so CS.UI.enumerateWebViews() can't detect CAPI's webviewId.
I was trying some workaround by coding JS Action invoker in CAPI text webview and transfer it to CSPro logic using CS.Clipboard.putText...
Hopefully, you are coming with a more direct way! But, activate the timer with a message is a very good approach! And think it's also possible to share data between CSPro and JS using the CS.Clipboard.putText.
Not for advanced users...Nor impossible... to CSPro, the most advanced CAPI SDK in the world!This is definitely for advanced users, but it is impossible.
Thanks again to the CSPro Developer Team!
Best
Last edited by htuser on January 28th, 2025, 8:19 pm, edited 1 time in total.
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Automatic skip after time limit on field
Thank you very much @Gregory and @htuser. Exactly what I want. I have adopted it and it works perfectly 
