Date post: | 02-Jul-2015 |
Category: |
Technology |
Upload: | drupalsib |
View: | 68 times |
Download: | 3 times |
Form API
AJAX-commands
OK
Form API
OK
OK
AJAX
AJAX
- Toyota
- Renault
- Porsche
- Выберите -
Добро пожаловать.
- PorscheПоздравляем!
Вам в подарок:
Porsche 911 Carrera
$form['offer_type'] = array(
'#type' => ‘select',
'#title' => t('Select please'),
'#options' => array( ... ),
'#ajax' => array(
'callback' => 'name_of_function',
'wrapper' => 'html-id-of-wrapper',
),
);
Form Builder
1. Form builder
2. Form validate
3. Form submit
+
4. AJAX-callback
custom_form_validate
custom_form
custom_form_submit
name_of_function
function name_of_function($form, $form_state) {
$html = ‘<div>’ . t(‘Hello!’) . ‘</div>’;
return $html;
}
1. HTML
Hello!
function name_of_function($form, $form_state) {
return $form;
}
2. Renderable array
OK
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,
);
}
3. 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,
);
23 / 05 / 2014