Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. $form['#attached']['js'] = array('(function ($){$(document).ready(function() { $(".form-item-field-name input").focus()});})(jQuery);' => array( 'type' => 'inline'));
  2.  
  3. function your_module_form_alter(&$form, &$form_state, $form_id) {
  4. if($form_id == 'my_form'){
  5. // Add JavaScript file
  6. $form['#attached']['js'] = array(drupal_get_path('module', 'your_module') . '/your_file.js');
  7.  
  8. // Or for inline JavaScript
  9. $form['#attached']['js'] = array('/* some javascript here */' => array( 'type' => 'inline'));
  10. }
  11. }
  12.  
  13. function HOOK_form_user_login_alter(&$form, &$form_state, $form_id) {
  14. //should also add JS focus code for iOS Safari
  15. $form['name']['#attributes'] = array('autofocus' => '');
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement