AaronLasseigne / active_interaction

:briefcase: Manage application specific business logic.
MIT License
2.07k stars 137 forks source link

Does array items accept default nil or not #515

Closed formigarafa closed 2 years ago

formigarafa commented 2 years ago

Array filter has this example on the top of the class: https://github.com/AaronLasseigne/active_interaction/blob/master/lib/active_interaction/filters/array_filter.rb#L18-L21

    #   @example
    #     array :ids do
    #       integer default: nil
    #     end

But on implementation has this: https://github.com/AaronLasseigne/active_interaction/blob/master/lib/active_interaction/filters/array_filter.rb#L108

  raise InvalidDefaultError, 'default values in array block' if filter.default?

Maybe I am missing something but it looks conflicting.

Just to be clear on the use-case I am trying to get the list of ids from a multi checkbox field and rails send params like this:

{resource_ids: ["", 3, 5]}

Rails would ignore that first item when more items are added to the list and take that array with only one empty string in probably to tell the difference between key not send and key sent with empty list.

Is this multiple checkbox use case supported?

AaronLasseigne commented 2 years ago

The documentation is correct. This sounds like a bug.

formigarafa commented 2 years ago

thank you, @AaronLasseigne. ❤️