Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set Nullable Fields to null #1553

Closed
TheNeikos opened this issue Feb 14, 2020 · 1 comment
Closed

Can't set Nullable Fields to null #1553

TheNeikos opened this issue Feb 14, 2020 · 1 comment

Comments

@TheNeikos
Copy link

  • What would you like to be able to do? Can you provide some examples?

I have a boolean field on my model that can have 3 values, "not set" -> NULL, "true" and "false. Right now, I can only switch between true/false but not `NULL.

  • How could we go about implementing that?

One could add a new option to Field::Boolean like 'nullable'. Although, this could be applied to all fields.

  • Can you think of other approaches to the problem?

Not really in this case

@pablobm
Copy link
Collaborator

pablobm commented Feb 14, 2020

The problem with implementing this with a checkbox is that a checkbox only has two states. There's no way to express the three states you require.

Instead, you could create a custom field type that shows something else, perhaps three radio buttons. These would send values null, true or false, and a controller that knows how to use it, perhaps by overriding Administrate::ApplicationController#resource_params.

A similar conversation was had recently at #1478

If you are not sure of how to do this, ask on StackOverflow and I'll try to answer there (use the tag "administrate").

@pablobm pablobm closed this as completed Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants