tags icon indicating copy to clipboard operation
tags copied to clipboard

CheckboxTag cannot be unselected with buffalo

Open dcardamo opened this issue 6 years ago • 1 comments

The docs say to do this:

<%= f.CheckboxTag({name: "IsPublic", label: " Is the talk public?"}) %>

but that gives this error:

(map[string]interface {}) is an invalid argument for f.CheckboxTag at pos 0: expected (string)

so it seems that the API should be to pass a string, and then a map as a second parameter. but if I change that to be

<%= f.CheckboxTag("IsPublic", {label: " Is the talk public?"}) %>

then it looks good ( I get my configured label ), but I can't actually change the value of the checkbox So the docs are definitely wrong on the wiki as I'm able to get further this way. The secondary problem is that if I do it this way then I can select a checkbox, but I cannot unselect a checkbox. By doing this instead I can unselect in buffalo successfully:

<%= f.CheckboxTag("IsPublic", {unchecked: false, label: " Is the talk public?"}) %>

dcardamo avatar Aug 12 '19 23:08 dcardamo

I believe the documentation in the Wiki is for a non-model form, using the form helper function, but you have a form updating a pop model, using the form_for helper function.

Here's the documentation on the gobuffalo site for the Checkbox tag function for the model form: https://gobuffalo.io/en/docs/forms#checkbox-tags

This can be super confusing because the form instance variable is the same, f, and the function name is the same, CheckboxTag, for both types of forms in all the documentation.

codegoalie avatar Nov 22 '19 19:11 codegoalie

Indeed, it seems like there is something that can be improved on the doc (and/or API).

Anyway, I am closing this issue since it was answered and is not active now. Please feel free to reopen it.

sio4 avatar Sep 04 '22 11:09 sio4