Yes / No Checkboxes?

Hi Johnny,

I see in this post that in V3 checkbox_boolean isn’t implemented… And as far as I can tell it doesn’t work trying it with code.

I would really like a forced yes / no choice presented to the user. The best I think I can do right now is:

$crud->fieldType('Active','dropdown',['0' => 'No', '1'=>'Yes']);

However, it permits the NULL value too. Yes, my database for historical reasons permits NULL, but I would prefer the user to pick yes or no. (And not have the NULL option). Ideally via a radio button since a drop down takes longer.

Any thoughts on how to best handle this?

Thanks,

Ira

I think GCE should have ‘radio’ field type.

@heruprambadi - only checkbox_boolen is in the field type list for V3.0.9 (GCE) but it does not appear to do anything. Hence the question.

Hello @iradave,

You are right, checkbox_boolean is not implemented. I forgot to remove it from the documentation. The main reason was that it wasn’t working as expected at the quick search. I will revisit this and let you know. Maybe I will add it to a future version.

Regards
Johnny

@iradave ,

I will also check the main issue that you’ve described and try to find a solution to your issue. For now as a work-around can you use callbackInsert | Grocery CRUD v3 and callbackUpdate | Grocery CRUD v3 as a solution?

3rd update :slight_smile:

However, it permits the NULL value too. Yes, my database for historical reasons permits NULL, but I would prefer the user to pick yes or no.

This is probably a bug. I will check it and let you know.

Regards
Johnny

Hello @iradave ,

I’ve investigated your comment:

However, it permits the NULL value too. Yes, my database for historical reasons permits NULL, but I would prefer the user to pick yes or no.

And this is the expected behaviour. Please keep in mind that in case you would like to not permit NULL values, either have it as required field with requiredFields | Grocery CRUD v3 , either to user callbackBeforeInsert and callbackBeforeUpdate and in case the user has empty value to change it to “0”

Let me know if that is ok for now for the dropdown list.

For the initial Yes/No Checkbox, I am still checking to see if I can have it to a short-term future version.

Regards
Johnny

Hi @Johnny,

Thanks for the suggested work arounds of callbackInsert and callbackUpdate. I think it would be more complicated to use those and that would make the UI a bit clumsy… I’ll wait for a radio button in a future release.

That said, I would argue that accepting a NULL is unexpected behavior. Yes it is valid in my MySQL field which is enumerated. However you see I only enumerated two values in the fieldType:

['0' => 'No', '1'=>'Yes']

The input routine should only allow those but not NULL. Another example if the table had enumerated values of (Yes, No, Maybe, Crazy) and one specified the fieldType with only Yes or No. In this case, the drop down only show Yes or No as choice. It shouldn’t show Maybe or Crazy.

Perhaps if one wanted to provide a NULL option then NULL would also go in the list like this:

['0' => 'No', '1'=>'Yes', NULL]

Does this make sensse?

Thanks,

Ira

Yes @iradave ,

Your suggestion makes totally sense. I will revisit the dropdown as you’ve suggested and let you know.

Regards
Johnny

1 Like