onfocus vs preproc

Discussions about creating CAPI applications to run on Android devices
Forum rules
New release: CSPro 8.0
Post Reply
Anne
Posts: 104
Joined: January 11th, 2012, 12:55 am

onfocus vs preproc

Post by Anne »

Hopefully, this is not a stupid question, but being a CSPro user for quite a few years now, it suddenly occured to me that I can't really see why you would want to use preproc at all on a CAPI application.

It made sense in times of CSPro as a data entry tool: The keyers would hardly ever move back to previous questions to correct things, and there were probably less logic anyway, as you would want to force the keyers to make judgements on the data they entered.

But in the times of tablets there is no way of predicting whether the interviewer moves backwards or forwards, and you probably want the preproc/onfocus to execute no matter what direction he moves, so we should probably (almost) always use onfocus instead of preproc..

..and I can't even come up with a counter example.. Only weird thing is that I never really thought about it before... :)

Maybe the CSPro people should make a point out of this in manuals (if I'm right)?

Anne
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: onfocus vs preproc

Post by josh »

I generally use onfocus for anything that changes the valueset or question text since those need to be updated no matter which way you come into the field. I use the preproc if I need to set the value of the variable in logic since I normally don't need to change the value when coming back to the field. It certainly doesn't hurt to modify the value of the variable in the onfocus but you shouldn't need to since in a properly structured application the prefill for the variable you set in the preproc should only depend on variables before the item whose value you are setting which will not have changed when you come back to the field.
Anne
Posts: 104
Joined: January 11th, 2012, 12:55 am

Re: onfocus vs preproc

Post by Anne »

Interesting..

I agree with the setting of valuesets and capi questions, but what if you have skips before the question? Shouldn't that also be done in an onfocus rather than a preproc?

(In general I prefer to put the skips in postprocs rather than preprocs/onfocus, but right now I have a questionnaire with the most crazy skips ever, so i decided to do it in the preproc as it's easier for the questionnaire designers)

Anne
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: onfocus vs preproc

Post by Gregory Martin »

There are other reasons to use preprocs. For example:
PROC MARITAL_STATUS

preproc

    if AGE < 12 then
        MARITAL_STATUS = 0;
        noinput;
    endif;
If you had that noinput in the onfocus, there would be no way to move backwards because every time you got to that field you would prefill in marital status and noinput (advancing to the next field).

Honestly, the reason that onfocus has become more popular is because of dynamically changing value sets or CAPI text on rosters. Generally any such changes depend on fields entered prior to the current field, but because on a roster there are many such sets of fields, it's required to change the values so that if you move backwards, for example, person 3's CAPI text doesn't show information about person 4.
Post Reply