This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

oskar.villani40843
oskar.villani40843

Hi there :) for learning reasons I'm currently trying to refurbish the inetis-list swith plugin/widget. Anything is going fine as long as I use the widget directly in a models columns.yaml

But using the widget in a list displayed as a relation in a form, I get the error: "AJAX handler 'onSwithFxListField' was not found. Of course it is defined in my plugin php but it does not seem to appear, when a related list is displayed.

![The error message] (https://drive.google.com/file/d/1ImA2uY4AiR0EkoxkAWaxVO9pE2j8j6pg/view?usp=sharing)

Well, if maybe markdown image integration is not set properly, please see the link for a screenshot

Any suggestions how to make this work? Thanks in advance!

Oskar

Last updated

daftspunky
daftspunky

It's hard to know what the problem is based on the supplied information. However, the best thing to do would be to carefully compare both plugins to see what part of the puzzle you are missing. If it works for the inetis plugin, then you have a working example to study

Good luck with it!

oskar.villani40843
oskar.villani40843

Hi daftspunk,

thanks for your advice, I did so, but could not find a significant difference. Anyhow by a good guess and some luck I found the reason: The JS/AJAX call implementation in the original plugin.php (from https://github.com/inetis-ch/oc-ListSwitch-plugin/blob/master/Plugin.php )seems to be somewhat mistyped...

    /**
     * Switch a boolean value of a model field
     * @return void
     */
    Controller::extend(function ($controller) {
        /** @var Controller $controller */
        $controller->addDynamicMethod('index_onSwitchInetisListField', function () use ($controller) {

           /* ... some stuff here ... */

            return $controller->listRefresh($controller->primaryDefinition);
        });
    });

Replacing the implementation

$controller->addDynamicMethod('index_onSwitchInetisListField', function () use ($controller) 

with

$controller->addDynamicMethod('onSwitchInetisListField', function () use ($controller) 

i.e simply without the leading "index_" anything seems to work fine. I'm wondering what's the purpose of this "index".

daftspunk said:

It's hard to know what the problem is based on the supplied information. However, the best thing to do would be to carefully compare both plugins to see what part of the puzzle you are missing. If it works for the inetis plugin, then you have a working example to study

Good luck with it!

daftspunky
daftspunky

Glad to hear it. The index_ prefix restricts the usage of that AJAX handler to a controller action with the name "index"; index is also the default action name when none is supplied

Interesting that this does not appear to be documented anywhere. We will get this fixed in the coming days

oskar.villani40843
oskar.villani40843

Hello daftspunk,

thanks a lot for this explanation!

Indeed there are some non-documented or hard to find features. The one thing I learned already is, that a lot of things are easy to implement in OctoberCMS as soon as one has found the how-to :)

What I really enjoy are examples like your playground on github ( https://github.com/octoberrain/test-plugin ) to get more familiar with features. To me OC it is the most fitting system to develop some web applications. That's a unique strength of OC way, way more convenient than doing so in Wordpress, Typo3 or Contao.

Best regards and looking forward seeing more teasers on the youtube OctoberCms Official channel ( https://www.youtube.com/channel/UCC9XsEDQxLwAzAvX-La4pXA :)))

Oskar

daftspunk said:

Glad to hear it. The index_ prefix restricts the usage of that AJAX handler to a controller action with the name "index"; index is also the default action name when none is supplied

Interesting that this does not appear to be documented anywhere. We will get this fixed in the coming days

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.