Skip to content

Decoding a multi-checkbox fieldset #33

@Ullaakut

Description

@Ullaakut

Hi! Thanks for your great library.

I have encountered an issue with decoding fieldsets:

        <fieldset>
            <legend>Select labels</legend>
            <input type="checkbox" name="labels" value="label1">label1
            <input type="checkbox" name="labels" value="label2">label2
            <input type="checkbox" name="labels" value="label3">label3
            <input type="checkbox" name="labels" value="label4">label4
        </fieldset>

When selecting multiple checkboxes, the form data is sent appropriately as expected:

INFO[2020-09-20T08:44:35+02:00] /submit/ content_type=application/x-www-form-urlencoded db=0s duration=1.374036ms form="{\"authenticity_token\":[\"MONVHBgDotwySs80XP5vV901VtmULCrk73Sxe5oYSN+hUpiIPKnGdO8DBRUlizJBmbkganMr4C6QfPNJsHnncg==\"],\"description\":[\"test\"],\"labels\":[\"label1\",\"label2\",\"label3\",\"label4\"], ...

But then when decoded into a []string only the first value is unmarshalled, and the []string results in:

BOUND ENTRY: &models.Entry{Title:"Test", Description:"Test", Labels:slices.String{"tileable"}}

For extra info, I don't think it matters but just in case, I'm using gobuffalo's Bind() function and the type I unmarshal into is not directly a []string but a wrapper around it, a slices.String from gobuffalo's pop/slices package.

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