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!";
}
id
to yourinput
to target it.jQuery.ajax(url, (data)=>{ jQuery('#your_input_id').val(data) })