jnastasi
Posts:
2
Registered:
Mar 5, 2009
|
|
Validator Question
Posted:
Mar 24, 2009 12:23 PM
|
|
|
|
Hi,
I have built a validator plug-in based on the MaxPercentage example. It sums the values selected by contiguous dropdown menus and displays the value in a numericResponse field on the next page. The validator is attached to the numericResponse field.
1. The setup requires a starting and ending question # 2. The numericResponse field is assumed to be the end question # + 1
It works fine until I try to display the value in the numericResponse field. The value is correct, so the data gathering and summation is proper. When I get to the next page, the numericResponse field is blank. IF I put a non-numeric value in there and press the Finish button, the proper value will be displayed. But, that is obviously wrong.
Here's the initial setup:
ResponseNumeric responseNumericToFill = (ResponseNumeric) respondent.getResponse(scoreQNo);
And how I access it (along with the debug line): responseNumericToFill.setValue(Integer.toString(score)); PluginUtil.info("ScorePlugin.validate(): Score: " + Integer.toString(score) );
The survey has three DropDown questions in one section and a numericResponse question in the last section. I've also attached the source to the plugin and the exported survey.
I'd appreciate any ideas as to why this is not displaying or, more accurately, displaying only when a non-numeric is answered.
Thanks Joe Nastasi
|
|
GinoAMelone
Posts:
1
From:
Cleveland, Ohio, USA
Registered:
Mar 24, 2009
|
|
Re: Validator Question
Posted:
Mar 24, 2009 6:49 PM
|
|
I'm trying to do something very similar. It seems to me that the behavior you're seeing is because the validation doesn't execute until after you submit a value for that question.
I think putting the validation on the last of your source questions should do what you want. But, then you need to write to a different question than the one being validated.
I plan to use your code to guide me in writing my plug-in. It will be my first.
|
|
jnastasi
Posts:
2
Registered:
Mar 5, 2009
|
|
Re: Validator Question
Posted:
Mar 25, 2009 3:38 PM
|
|
That is indeed the problem AND solution. I actually have it on the first question for simplicity: the business folks who create the surveys always know it's on the top. That works in our situation.
Best of luck!
|
|
irina
Posts:
315
From:
Norway, Oslo
Registered:
Sep 4, 2003
|
|
Re: Validator Question
Posted:
Apr 14, 2009 9:52 PM
|
|
What you are doing it not actually a validation. You need to prepopulate the numeric answer and not to validate it. Here is what you need to do:
1. add "implements IEventListener" to your plugin 2. add your plugin to the event bus like this: public void start() { EventBusManager eventMgr = EventBusManager.instance(); eventMgr.addListener(this, EventBusManager.BUS_TYPE_SURVEY, EventBusManager.EVENT_TYPE_DISPLAY_QUESTION); }
3. implement handleEvent(Event event) method. Below is a short version. You will of cause need to pass all the nessesary variables and put try/catch around.
if (event instanceof DisplayQuestionEvent) { DisplayQuestionEvent qEvent = (DisplayQuestionEvent) event; if (qEvent.getQuestionNo() != scoreQNo) { long respondentId = qEvent.getRespondentId(); Respondent respondent = SurveyManager.getRespondentForSurvey(respondentId, surveyId); ResponseNumeric numResponse = (ResponseNumeric) respondent.getResponse(scoreQNo); numResponse.setValue(valueToFill); } }
You can keep the simple validation screen to set up the start and stop questions but move the calculation logic out from the validation method and to the event method.
|
|
|
|
|