These are chat archives for dry-rb/chat

20th
Sep 2018
Piotr Solnica
@solnic
Sep 20 2018 07:07
@swinner2 you can reject blank values prior validation
validation logic should not be bothered by a messy input
Sean Winner
@swinner2
Sep 20 2018 14:54
@solnic Yep I was confused because I didn’t realize rails adds the hidden_field to multi-select form elements. So I created a type that will remove the blank field since the first member of the array will always be a blank value.
  MultiSelectInputArray = Types::Array.constructor do |array|
    # (array.size == 1) means that the array is [""] and nothing was selected. So, we return nil.
    if array.size == 1 && array.first.empty?
      nil
    else
      array.delete("")
      array
    end
  end