Class: Quby::Compiler::Entities::Questions::CheckboxQuestion
- Inherits:
-
Quby::Compiler::Entities::Question
- Object
- Item
- Quby::Compiler::Entities::Question
- Quby::Compiler::Entities::Questions::CheckboxQuestion
- Defined in:
- lib/quby/compiler/entities/questions/checkbox_question.rb
Constant Summary
Constants inherited from Quby::Compiler::Entities::Question
Quby::Compiler::Entities::Question::MARKDOWN_ATTRIBUTES
Instance Attribute Summary collapse
-
#check_all_option ⇒ Object
checkbox option that checks all other options on check.
-
#maximum_checked_allowed ⇒ Object
checkbox option that allows to select a maximum amount of checkboxes.
-
#minimum_checked_required ⇒ Object
checkbox option that forces to select a minimum amount of checkboxes.
-
#uncheck_all_option ⇒ Object
checkbox option that unchecks all other options on check.
Attributes inherited from Quby::Compiler::Entities::Question
#allow_blank_titles, #allow_duplicate_option_values, #as, #autocomplete, #col_span, #cols, #context_free_title, #default_invisible, #default_position, #dependencies, #depends_on, #description, #deselectable, #disallow_bulk, #display_modes, #extra_data, #group_maximum_answered, #group_minimum_answered, #hidden, #input_data, #key, #labels, #lines, #options, #parent, #parent_option_key, #question_group, #questionnaire, #row_span, #sbg_key, #score_header, #sets_textvar, #show_values, #size, #table, #title, #title_question, #type, #unit, #validations
Attributes inherited from Item
#presentation, #raw_content, #switch_cycle
Instance Method Summary collapse
- #answer_keys ⇒ Object
- #as_json(options = {}) ⇒ Object
- #claimed_keys ⇒ Object
-
#initialize(key, options = {}) ⇒ CheckboxQuestion
constructor
A new instance of CheckboxQuestion.
Methods inherited from Quby::Compiler::Entities::Question
#context_free_title_or_title, #expand_depends_on_input_keys, #hidden?, #html_id, #input_keys, #key_in_use?, #maximum, #minimum, #set_depends_on, #show_values_in_mode?, #subquestion?, #subquestions, #title_question?, #view_selector
Constructor Details
#initialize(key, options = {}) ⇒ CheckboxQuestion
Returns a new instance of CheckboxQuestion.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/quby/compiler/entities/questions/checkbox_question.rb', line 20 def initialize(key, = {}) super @check_all_option = [:check_all_option] @uncheck_all_option = [:uncheck_all_option] @maximum_checked_allowed = [:maximum_checked_allowed] @minimum_checked_required = [:minimum_checked_required] if @check_all_option @validations << {type: :not_all_checked, check_all_key: @check_all_option, explanation: [:error_explanation]} end if @uncheck_all_option @validations << {type: :too_many_checked, uncheck_all_key: @uncheck_all_option, explanation: [:error_explanation]} end if @maximum_checked_allowed @validations << {type: :maximum_checked_allowed, maximum_checked_value: @maximum_checked_allowed, explanation: [:error_explanation]} end if @minimum_checked_required @validations << {type: :minimum_checked_required, minimum_checked_value: @minimum_checked_required, explanation: [:error_explanation]} end end |
Instance Attribute Details
#check_all_option ⇒ Object
checkbox option that checks all other options on check
9 10 11 |
# File 'lib/quby/compiler/entities/questions/checkbox_question.rb', line 9 def check_all_option @check_all_option end |
#maximum_checked_allowed ⇒ Object
checkbox option that allows to select a maximum amount of checkboxes
15 16 17 |
# File 'lib/quby/compiler/entities/questions/checkbox_question.rb', line 15 def maximum_checked_allowed @maximum_checked_allowed end |
#minimum_checked_required ⇒ Object
checkbox option that forces to select a minimum amount of checkboxes
18 19 20 |
# File 'lib/quby/compiler/entities/questions/checkbox_question.rb', line 18 def minimum_checked_required @minimum_checked_required end |
#uncheck_all_option ⇒ Object
checkbox option that unchecks all other options on check
12 13 14 |
# File 'lib/quby/compiler/entities/questions/checkbox_question.rb', line 12 def uncheck_all_option @uncheck_all_option end |
Instance Method Details
#answer_keys ⇒ Object
57 58 59 60 |
# File 'lib/quby/compiler/entities/questions/checkbox_question.rb', line 57 def answer_keys # Some options don't have a key (inner_title), they are stripped. .map { |opt| opt.input_key }.compact end |
#as_json(options = {}) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/quby/compiler/entities/questions/checkbox_question.rb', line 62 def as_json( = {}) super.tap do |json| json[:children] = @options.as_json json[:checkAllOption] = check_all_option if check_all_option.present? json[:uncheckAllOption] = uncheck_all_option if uncheck_all_option.present? end end |
#claimed_keys ⇒ Object
53 54 55 |
# File 'lib/quby/compiler/entities/questions/checkbox_question.rb', line 53 def claimed_keys [key] end |