Toggle custom enum yes/no field in advanced module

edited June 2011 in Modules
The database table I'm working with uses the column 'blocked' as a boolean and I'm also using published.
It seems that Fuel recognizes 'active' and 'published' as fields that you can click to set to yes or no.
What I'm trying to do is get the same functionality for 'blocked', is there any way to achieve this?

Comments

  • edited 11:48AM
    'active' and 'published' fields are given special treatment in FUEL in a couple areas. There currently isn't an easy way to replicate that functionality without changing a few things. That said, I'll try and point you in the right direction:

    1. The first is the list view table, where it allows you to toggle the item between a "yes" and "no" value. The toggle functionality in the list view is done by using a column formatter function to apply to that column. This is done around line 272 of the fuel/modules/fuel/controller/module.php controller. There is also some corresponding javascript in fuel/modules/assets/js/fuel/controller/BaseFuelController.js file on the tableCallback method around line 916.

    2. The second is that in the form view, there is a button in the top button bar, that allows you to toggle between the to states. You can control what buttons appear in your module by changing the "item_actions" module configuration parameter in your fuel/application/config/MY_fuel_modules.php. In your case, you would need to create an "others" which is somewhat explained here:
    http://www.getfuelcms.com/user_guide/modules/simple

    3. The third, is that in the base_model_module, the model that most model's inherit from, there is a _common_query() method that will automatically exclude those values with a published or active state of "no" are excluded from the query results when viewing the live site. You could duplicate that functionality in your models _common_query() method (be sure to call the parent::_common_query() in your model)

    Hope this helps.
  • edited December 2012
    I wanted to have the ajax-toggle between yes/no on the list view in the fuel admin (i.e. point 1 of 'admin's answer) for my 'featured_product' field of my Products_model simple module. To my joy, after a little looking at the code, all I needed to do was add :
    public $boolean_fields = array('featured_product');

    to my simple modules model class (e.g.application/models/Products_model, in my case)
    And this gave me the desired functionality on Fuel 1.0 beta.

    Great stuff!
    Thanks
    Guy
  • edited 11:48AM
    Yes... boolean fields have been added to 1.0 to distinguish between tinyint fields and a tinyint field that is actually an enum of 1,0.
Sign In or Register to comment.