I’ve a form class named "ShoppingCartForm" which extends FormBase
I’ve made the following method into the form class.
public function editAddress(array &$form, FormStateInterface $form_state) {
return 'return here';
}
Now I need to reach this method with AJAX, for which I wrote the following JavaScript code.
$(document).on('click', '.edit-stored-address', function(){
$.ajax({
url: Drupal.url('ibcart/edit_address'),
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (response) {
console.log(response);
}
});
});
The route is defined as follows.
ibcart.edit_shoppingcart_address_form:
path: '/ibcart/edit_address'
defaults:
_form: 'DrupalibcartFormShoppingCartForm::editAddress'
_title: 'Edit address'
methods: [GET]
requirements:
_permission: 'access content'
When I click on the Edit link, I get the following error.
InvalidArgumentException: Class "DrupalibcartFormShoppingCartForm::editAddress" does not exist. in DrupalCoreDependencyInjectionClassResolver->getInstanceFromDefinition() (line 24 of /var/www/html/ibfd/web/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).
Any hints?