Toggle field in list view

edited August 2015 in Modules
Hi,

if I have a published column in my database table the CMS automatically creates a toggle field in the list view where I can click on to toggle the enum value.

How can I use this behaviour for my own enum fields?

Comments

  • edited 12:19PM
    Try using the "boolean_fields" model parameter to specify an enum with two values or a boolean field type:
    public $boolean_fields = array('my_enum');
    Fields with the name of "active" or "published" are automatically set to toggle in FUEL.
  • edited 12:19PM
    Hi,
    boolean_fields did it. Thanks! I had defined it at the wrong place. I did it in the fuel_Modules Config file... doh... :-)
  • edited 12:19PM
    Hi,
    ok... one issue remains... NOw the fields are displayed as toggle fields, but on clicking nothing happens... do I have to implement a hook or overwrite a method?
  • Using Firebug, check the console to see what POST is sent when you click the toggle. You should have something along the lines of ./fuel/my_module/toggle_off/7/active where 'active' is your fieldname and '7' is the value your record's primary key field.

    I have a problem with my setup where my fieldname is actually assetActive and in the model's list_view function I'm aliasing it to 'active' so the column title looks nice (eg. SELECT assetActive as active). Doing this screws up the toggle functionality and the ajax URL is generated using the column header value.

    Admin: Any suggestions? Cheers
  • edited 12:19PM
    Hi,

    if you select a field in list_items with assetActive as active then you have to define the public $boolean_fields with the value active and not with assetActive.
    Perhaps this is your error?

    KR
    Habib
  • edited 12:19PM
    Hi,

    in the console I see the post as http://demo.feuerwehr-bs.de/fuel/mannschaft_members/toggle_off/10/beruf_zeigen ... but where do I have to implement this "toggle_off"? do I just have to write a method in my model? or is it a hook I have to overwrite?
  • edited 12:19PM
    hmm ok.. I think i got the problem...
    in my list_items I overwrite the select with show_image as bild_zeigen.
    Now in the post it says /toggle_off/10/bild_zeigen instead of toggle_off/10/show_image

    @Admin: is there a possibility to get this working with using the select show_image as bild_zeigen functionality?
  • edited 12:19PM
    Did you add "bild_zeigen" to the $boolean_fields property of the model?
  • edited 12:19PM
    In my model I have
    public $boolean_fields = array('beruf_zeigen', 'geburtsdatum_zeigen', 'eintritt_zeigen', 'bild_zeigen'); public function list_items($limit = NULL, $offset = 0, $col = 'id', $order = 'asc', $just_count = FALSE) { $this->db->join('mannschaft_sections', 'mannschaft_sections.id = mannschaft_members.section_id'); $this->db->join('mannschaft_teams', 'mannschaft_teams.id = mannschaft_members.team_id'); $this->db->order_by('mannschaft_members.section_id asc, mannschaft_members.name asc, mannschaft_members.vorname asc'); $this->db->select('mannschaft_members.id as id, mannschaft_sections.name as abteilung, mannschaft_members.name as name, mannschaft_members.vorname as vorname, mannschaft_members.show_image as bild_zeigen, mannschaft_members.show_beruf as beruf_zeigen, mannschaft_members.show_geburtstag as geburtsdatum_zeigen, mannschaft_members.show_eintrittsdatum as eintritt_zeigen, published'); $data = parent::list_items($limit, $offset, $col, $order, $just_count); return $data; }
  • edited 12:19PM
    FUEL currently doesn't support that unfortunately.

    Perhaps a change to the $boolean_fields property where you can pass it a $key=>$val as well. If the key is a string it will use that instead of the value which is the alias to that value. This would need to be changed in a few places including fuel/modules/fuel/core/MY_Model.php, fuel/modules/fuel/libraries/Base_module_model.php and in the fuel/modules/fuel/controllers/module.php files.
Sign In or Register to comment.