3

Build form :

public function buildForm(array $form, FormStateInterface $form_state) {
 $form['service_name'] = [
    '#type' => 'textfield',
    '#attributes' => [
        'placeholder' => t('Поиск по названию'),
        'class' => [
            'input',
            'input_small',
            'input_bordered',
            'input-with-icon',
            'input-with-icon_right',
            'input-search-icon',
            'input_services-search'
        ]
    ]
];

$options = $this->getServicesOrganizations();

$form['services_organizations'] = [
    '#type' => 'select',
    '#options' => $options,
    '#attributes' => [
        'class' => [
            'input',
            'select_small',
            'select_standart',
            'input_bordered',
            'input-with-icon',
            'input-with-icon_right',
            'input-select-arrow-icon'
        ]
    ]
];

$form['services_search_submit'] = [
    '#type' => 'submit',
    '#name' => 'submit',
    '#value' => $this->t('Найти'),
    '#ajax' => [
        'callback' => '::ajaxSubmitCallback',
        'event' => 'click',
        'progress' => [
            'type' => 'throbber'
        ]
    ],
    '#attributes' => [
        'class' => [
            'button',
            'button_small',
            'button_standart',
            'button_text-white'
        ]
    ]
];

$form['system_messages'] = [
    '#markup' => '<div id="form-system-messages"></div>',
    '#weight' => 100
];

return $form;

}

Callback method:

public function ajaxSubmitCallback(array &$form, FormStateInterface       $formState)
{
    $ajax_response = new AjaxResponse();
    $ajax_response->addCommand(new HtmlCommand('#form-system-messages',      'test'));
    return $ajax_response;
}

When I click on submit button in form, in browser console appears error:

Uncaught AjaxError: 
Возникла AJAX HTTP ошибка.
Полученный код HTTP: 500
Следует отладочная информация.
Путь: /services?ajax_form=1
Текст Состояния: Internal Server Error
Текст Ответа: {}

And in logs:

Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\HttpException: "The specified #ajax callback is empty or not callable." at /var/www/drupal/stas -m.mfc/web/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php line 67

Where i make mistake?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.