Initialising methods from custom controller js using JQX

edited April 2012 in Modules
Hi, I'm having difficulty understanding how to initiate a method from a custom js controller.

I've added the controller js file name to the target module in MY_fuel_modules:

$config['modules']['news'] = array( 'display_field' => 'title', 'instructions' => '', 'archivable' => TRUE, 'preview_path' => 'news/item/{id}', 'js_controller' => 'NewsController', // custom js for this admin module 'js_controller_params' => array() );

and in NewsController.js I have:

jqx.load('plugin', 'jquery.tagsinput.min'); fuel.controller.NewsController = jqx.createController(fuel.controller.BaseFuelController, { init: function(initObj){ this._super(initObj); }, auto_suggest: function() { $('.tagsuggest').tagsInput({ // initialise tagsInput params }); } });

So the tagsInput plugin loads OK, but how do I initiate "auto_suggest" using JQX? I'm not sure what parameters to pass in 'js_controller_params' - the JQX documentation is a bit sparse. I've tried 'method' => 'auto_suggest' but there is already 'add_edit' functionality with that key, and it seems to have precedence.

Obviously I've copied the createController object construction from the PageController.js, but I'm not sure if I even need to do that? If I create a $(document).ready() with the plugin initialisation in newsController.js, then this suffices, but this isn't the FUEL way!

Comments

  • edited 1:35AM
    The add_edit method is what get's executed when you are editing a module record. To add additional functionality with jQX, you will need to override the add_edit method and call it's parent method:
    jqx.load('plugin', 'jquery.tagsinput.min'); fuel.controller.NewsController = jqx.createController(fuel.controller.BaseFuelController, { init: function(initObj){ this._super(initObj); }, add_edit: function(){ this._super(); this.auto_suggest(); }, auto_suggest: function() { $('.tagsuggest').tagsInput({ // initialise tagsInput params }); } });
    Alternatively, you can also just use the module's "js" parameter to include a normal javascript file.
  • edited April 2012
    Thanks - as usual, it's an easier solution in Fuel CMS than I imagine. The tagging input now works very nicely.

    My admiration of Fuel CMS keeps growing, it's really a magnificent project.
Sign In or Register to comment.