# File lib/smerf_system_helpers.rb, line 51 def validate_sub_question(question, responses, form) # Retrieve the owner object of this subquestion answer_object = smerf_get_owner_object(question, form) # Make sure owner object is a SmerfAnswer raise(RuntimeError, "Owner object not a SmerfAnswer") if (!answer_object.kind_of?(SmerfAnswer)) # Get the answer code answer_code = answer_object.code # Retrieve the owner object of the answer question_object = smerf_get_owner_object(answer_object, form) # 1. Make sure that the answer that relates to this subsequestion # has the correct response, e.g. # Select your skills # Banker # Builder # ... # Other # Please specify # We want to make sure 'Other' was selected if the 'Please specify' # subquestion has an answer # # Check if this subquestion has an answer if (smerf_question_answered?(question, responses)) # Check if the correct answer selected if (!smerf_question_has_answer?(question_object, responses, answer_code)) return "'#{answer_object.answer}' needs to be selected" end end # 2. Make sure that if an answer that has a subquestion is answered that # the subquestion has an answer, e.g. # # Select your skills # Banker # Builder # ... # Other # Please specify # We want to make sure that if 'Other' was selected the 'Please specify' # subquestion has an answer # # Check if the answer this subquestion relates to has been answered if (smerf_question_has_answer?(question_object, responses, answer_code)) # Make sure the subquestion has been answered if (!smerf_question_answered?(question, responses)) return "'#{answer_object.answer}' needs additional information" end end return nil end