Boolean Fields
- Single Page
Posted 04 April 2012 - 20:10 PM
I have looked over the examples, and have not seen something that allows this. I am sure I am not the only person who would appreciate a feature like that.
Thanks
Posted 04 April 2012 - 21:28 PM
$crud->change_field_type('has_categories', 'true_false');
and you will have this result --> [attachment=92:status.png]
If you want to change the "active" or "inactive" string (for example "yes" or "no")it is hardcoded at grocery CRUD library ( application/libraries/grocery_crud.php at line 1219 )
....
protected $default_true_false_text = array('inactive' , 'active');
....
so for now just change this at the grocery_crud library
Posted 18 May 2012 - 13:57 PM
Just for info, after i read this topic, for french users i have changed this :
protected $default_true_false_text = array('non' , 'oui');
it didn't work and got me mad
Now, since v1.2.1 we have to change it in assets/grocery_crud/languages/(mylang).php...
No longer need to modify it in the library.
Posted 27 September 2012 - 04:29 AM
e.g. I want to have one boolean field with values ("yes", "no") and another one with values ("available", "unavailable"). Is there any way to achieve this?
Changing the default boolean string only allows for one custom value.
Posted 20 February 2013 - 18:25 PM
I second HumbleMonk's suggestion of having different label options. Also, an option to display the field as a single checkbox instead of radio buttons would be nice.
Posted 20 February 2013 - 22:38 PM
Use the field_type to achieve what you want. Possibly the enum field type for you [member=HumbleMonk] and multiselect with one item within the array for you [member=rothkj1022].
Posted 14 June 2013 - 16:34 PM
Use the field_type to achieve what you want. Possibly the enum field type for you [member=HumbleMonk] and multiselect with one item within the array for you [member=rothkj1022].
I can see how setting your own enums using field_type is good for changing the label options. That's all good and I think solves the multiple label options issue.
The other issue of having a simple boolean checkbox isn't covered by what you suggested, though. For some boolean values I think it would be more user-friendly to offer just a single checkbox (with no value displayed), instead of 2 radio buttons with yes and no values. If the checkbox is checked, value is true. If not checked, false.
Posted 15 June 2013 - 08:11 AM
The other issue of having a simple boolean checkbox isn't covered by what you suggested, though. For some boolean values I think it would be more user-friendly to offer just a single checkbox (with no value displayed), instead of 2 radio buttons with yes and no values. If the checkbox is checked, value is true. If not checked, false.
This is true what you point out. At least at the moment there isn't such a functionality of a checkbox element.
Posted 21 November 2013 - 18:24 PM
I'm looking for some sort of a callback_read_field() functionality, so that true and false are not just shown as "1" or "" (nothing for 0). If I could just put this in a callback on the read field, I could change 1 to Yes and "else" to No...
Or is there another way to achieve this?
Posted 11 December 2013 - 03:21 AM
I did it this way:
$crud->field_type('active', 'dropdown', array('1' => 'Yes', '0' => 'No'));
Posted 17 July 2014 - 14:29 PM
I'm looking for some sort of a callback_read_field() functionality, so that true and false are not just shown as "1" or "" (nothing for 0). If I could just put this in a callback on the read field, I could change 1 to Yes and "else" to No...
Or is there another way to achieve this?
You can use callback_field().
Posted 17 July 2014 - 15:00 PM
That was the way that really worked for me (no changes necessary on core):
$crud->field_type('utiliza_epi', 'true_false', array('No', 'Yes'));
Posted 19 July 2014 - 11:18 AM
Thanks to this... :) I'm always looking for solutions that doesn't involve touching the original code of groceryCRUD... thanks!
Posted 01 August 2014 - 16:01 PM
I just noticed that in read() mode (displayed when view button is clicked) when the value is '0' or 'false' nothing is displayed. So I manage to get a solution by:
1.) Creating a table called "tblBool" with this structure:
2.) Set relation to this table so that the field that needs the "YES or NO" value will look upon it:
Code:
// Sets dropdown list (Reviewed bool) $crud->set_relation('qb_reviewed_id','tblbool','bool_value');
Output (This is what it looks like during add / edit):
Output (this is what it looks like upon clicking the view button /read() mode):
Problem solved ;). I just hope i helped someone with the same issues! Happy GCing! :D
Posted 23 January 2019 - 18:05 PM
Thank you larasmith,
unfortunately the picture files don't exist anymore. Could you upload them again, please? Thank you.
Cheers