Skip to content

Support for multiple checked checkboxes #57

Description

@bigforcegun

Checkboxes with collection now support only one checked checkbox, when select with multiple: 'multiple' support multiple selected items.

I suggest change method in Formular::Element::Modules::Checkable

def is_checked?
    !options[:checked].nil? || reader_value == options[:value]
end

to something like this

def is_checked?
    return !options[:checked].nil? || reader_value == options[:value] unless reader_value.is_a?(Array)
    reader_value.map(&:to_s).include?(options[:value].to_s) # TODO Perf improvement here - do we need the map?
end

aka in Select Element

def item_is_selected(option_val, current_val, multiple)
    return option_val == current_val.to_s unless multiple && current_val.is_a?(Array)
    current_val.map(&:to_s).include?(option_val) # TODO Perf improvement here - do we need the map?
end

Why?

It's unusual behavior in form builder with checkboxes. Array mean multiple choises and multiple checked elements.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions