| Module | SmerfSystemHelpers |
| In: |
lib/smerf_system_helpers.rb
|
This module contains some standard helper methods used by smerf.
All validation methods need to take three parameters:
| question: | The SmerfQuestion object to be validated |
| responses: | Hash containing user responses keyed using the question code |
| form: | Hash that contains all form objects including groups, questions and answers |
The method needs to return an empty string or nil if no errors or if there is an error then an error message describing the error should be returned.
Within the form definition file you specify if a validation is required on a question by specifying which methods within this module should be called to perform that validation, e.g.
specify_your_age:
code: g1q1 type: singlechoice sort_order: 1 question: | Specify your ages help: | Select the <b>one</b> that apply validation: validation_mandatory
Multiple validation methods can be specified by comma separating each method name.
This method retrieves the answer to the supplied question, if no answer found it will return nil. This method may return a hash containing all answers if the question allows multiple choices.
This method will check if the question has the answer passed as a parameter. Some questions allow multiple answers so we need to check if one of the answers is equal to the supplied answer.
This method will perform two checks:
This validation method is called from a subquestion, so the object parameter should be a subquestion