1

I have this customfield plugin where the user can select a folder in a popup, the call should be ajax based. The form-"field" including AJAX call etc. works already in some of my modules where the Ajax call goes via com_ajax into the module class and calls there MethodNameAjax. But i'm not able to bring this to work in my customfield module...

Where do i have to write in my Ajax Response Point & how?

customfield.php:

class PlgFieldsCustomfieldname extends FieldsListPlugin{ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form){...} } 

then inside models/fields/modalfolderselect.php the formfield for the "selection":

class JFormFieldModalFolderSelect extends JFormField{ protected function getInput(){ ... Field render ... } protected function getLabel(){ ... } } 

And the JS (for the modal and the AJAX Call from backend) /assets/modalfolderselect.js:

function getFilesystemAjax(path = ''){ let data = { path:path, }; let request = { 'data': JSON.stringify(data), 'format': 'json', 'option':'com_ajax', 'group': 'fields', (also tried 'Fields' here) 'plugin': 'customfieldname', 'method': 'listfilesystem' }; return jQuery.ajax({ url: '/index.php', type : 'GET', data: request, dataType:'json' }); } 

My problem now is, the plugin itself is not of type "Ajax" and it does not has to be because it is a customfield that has to extend FieldsListPlugin - and also the form field itself is has to extend JFormField... So i've found a hint that you can send the "group" as query option - unfortunately this is not enough. I need at least a simple example code how the AJAX call into a plugin in this scenario will work...

At least i've tried to put in this methods on various locations in my code without any response / error log at all.

public ?static? function onAjaxListfilesystem(){ error_log("AJAX Call!"); return "Ajax Call!"; } 
1
  • May I suggest a different approach? You may handle it directly in the browser, in the jQuery.ajax callback, simply add an id to your input to target it. jQuery.ajax(url, (data)=>{ jQuery('#your_input_id').val(data) }) Commented Mar 9, 2022 at 19:48

1 Answer 1

2

Plugins don't use method parameter. Instead the value you currently have there should be used in plugin parameter. This is because com_ajax dispatches an event rather than calling a specific method of a specific plugin. So the request data should be this:

let request = { 'data': JSON.stringify(data), 'format': 'json', 'option':'com_ajax', 'group': 'fields', 'plugin': 'listfilesystem' }; 
1
  • ok wow Plugin: class PlgFieldsCustomfieldname extends FieldsListPlugin{... public static function onAjaxCustomfieldname{...} } worked now thanks! now i can go on Commented Mar 10, 2022 at 7:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.