function js_callback_examples_form in JS Callback Handler 7.2
Menu callback for "js-callback-examples".
1 string reference to 'js_callback_examples_form'
- js_callback_examples_menu in js_callback_examples/
js_callback_examples.module - Implements hook_menu().
File
- js_callback_examples/
js_callback_examples.module, line 67 - Provides examples on how to use the JS module API.
Code
function js_callback_examples_form($form, $form_state) {
$form['#attached']['library'][] = array(
'js',
'js',
);
$form['#attached']['js'][drupal_get_path('module', 'js_callback_examples') . '/js_callback_examples.js'] = array();
$form['intro'] = array(
'#markup' => t('<p>This example page will show you examples on how each of these callbacks work using the JS module API.</p>'),
);
$submit = array(
'#type' => 'submit',
'#value' => t('Send'),
'#js_callback' => array(
'js_callback_examples' => 'get_uid',
),
);
$submit_code = $submit;
$description = t('Use <code>#js_callback</code> on elements (like this submit button) to automatically generate the necessary data attributes. It takes an associative array where the key is the module name and the value is the callback.');
$description .= '<pre><code>' . htmlentities(var_export($submit_code, TRUE)) . '</code></pre>';
$description .= '<pre><code>' . htmlentities(render($submit_code)) . '</code></pre>';
$form['get_uid'] = array(
'#type' => 'fieldset',
'#title' => t('Get UID (using #js_callback and $.fn.jsCallback())'),
'#description' => $description,
'#attributes' => array(
'data-js-type' => 'callback',
),
);
$form['get_uid']['first_name'] = array(
'#type' => 'textfield',
'#title' => t('Enter your name:'),
);
$form['get_uid']['actions'] = array(
'#type' => 'actions',
);
$form['get_uid']['actions']['submit'] = $submit;
$form['get_uid']['results'] = array(
'#type' => 'fieldset',
'#title' => t('Results'),
'#attributes' => array(
'class' => array(
'results',
),
),
'#value' => '<pre><code></code></pre>',
// Needs high weight so it appears after actions.
'#weight' => 1000,
);
$items = array();
$items[] = l(t('Access Denied'), 'js-callback-access-denied');
$items[] = l(t('Redirect'), 'js-callback-redirect');
$items[] = l(t('Admin'), 'admin');
$items[] = l(t('Front'), '<front>');
$form['using_js_get'] = array(
'#type' => 'fieldset',
'#title' => t('Using $.jsGet()'),
'#description' => t('Click the links below to see the results.'),
'#attributes' => array(
'data-js-type' => 'get',
),
'links' => array(
'#theme' => 'item_list',
'#items' => $items,
),
'results' => array(
'#type' => 'fieldset',
'#title' => t('Results'),
'#attributes' => array(
'class' => array(
'results',
),
),
'#value' => '<pre><code></code></pre>',
),
);
return $form;
}