Михаил Крайнюк. form api: ajax-commands

10
Form API AJAX-commands

Upload: ksenia-rogachenko

Post on 21-Feb-2017

143 views

Category:

Internet


3 download

TRANSCRIPT

Form API

AJAX-commands

OK

Form API

OK

OK

$form['offer_type'] = array(

'#type' => ‘select',

'#title' => t('Select please'),

'#options' => array( ... ),

'#ajax' => array(

'callback' => 'name_of_function',

'wrapper' => 'html-id-of-wrapper',

),

);

- Toyota

- Renault

- Porsche

- Выберите -Поздравляем!

Вам в подарок:

Porsche 911 Carrera

function name_of_function($form, $form_state) {

$html = ‘<div>’ . t(‘Hello!’) . ‘</div>’;

return $html;

}

1. HTML

Hello!

function name_of_function($form, $form_state) {

$cmd = array();

$cmd[] = ajax_command_replace(NULL, $output);

$cmd[] = ajax_command_prepend(NULL, theme('status_messages'));

return array(

'#type' => 'ajax',

'#commands' => $cmd,

);

}

2. Commands

Hello!

Готово!

AJAX-commandsajax_command_before

ajax_command_changed

ajax_command_css

ajax_command_dataajax_command_html

ajax_command_insert

ajax_command_invoke

ajax_command_prepend

ajax_command_remove

ajax_command_replace

ajax_command_restripe

ajax_command_settings

ajax_command_after

ajax_command_alert

ajax_command_append

Нужно больше?

Собственные AJAX-commands

(function($) {

Drupal.ajax.prototype.commands.my_func = function(ajax, response, status) {

document.title = response.title;

}

} (jQuery));

$cmd = array();

$cmd[] = array(‘command‘ => ‘my_func', ‘title‘ => $page_title . ‘!!!‘);

$cmd[] = ajax_command_replace(NULL, $output);

return array(

'#type' => 'ajax',

'#commands' => $cmd,

);

Спасибо!

Крайнюк Михаил

[email protected]