Commit 5fc858b2 authored by alexpott's avatar alexpott
Browse files

Issue #297209 by nod_, dwees, bdone: Remove 'Attach' button.

parent 07525d78
...@@ -43,6 +43,20 @@ Drupal.behaviors.fileValidateAutoAttach = { ...@@ -43,6 +43,20 @@ Drupal.behaviors.fileValidateAutoAttach = {
} }
}; };
/**
* Attach behaviors to managed file element upload fields.
*/
Drupal.behaviors.fileAutoUpload = {
attach: function (context) {
$(context).find('input[type="file"]').once('auto-file-upload').on('change.autoFileUpload', Drupal.file.triggerUploadButton);
},
detach: function (context, setting, trigger) {
if (trigger === 'unload') {
$(context).find('input[type="file"]').removeOnce('auto-file-upload').off('.autoFileUpload');
}
}
};
/** /**
* Attach behaviors to the file upload and remove buttons. * Attach behaviors to the file upload and remove buttons.
*/ */
...@@ -104,6 +118,12 @@ Drupal.file = Drupal.file || { ...@@ -104,6 +118,12 @@ Drupal.file = Drupal.file || {
} }
} }
}, },
/**
* Trigger the upload_button mouse event to auto-upload as a managed file.
*/
triggerUploadButton: function (event){
$(event.target).closest('.form-managed-file').find('.form-submit').trigger('mousedown');
},
/** /**
* Prevent file uploads when using buttons not intended to upload. * Prevent file uploads when using buttons not intended to upload.
*/ */
......
...@@ -1158,6 +1158,7 @@ function file_managed_file_process($element, &$form_state, $form) { ...@@ -1158,6 +1158,7 @@ function file_managed_file_process($element, &$form_state, $form) {
'#name' => $parents_prefix . '_upload_button', '#name' => $parents_prefix . '_upload_button',
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Upload'), '#value' => t('Upload'),
'#attributes' => array('class' => array('js-hide')),
'#validate' => array(), '#validate' => array(),
'#submit' => array('file_managed_file_submit'), '#submit' => array('file_managed_file_submit'),
'#limit_validation_errors' => array($element['#parents']), '#limit_validation_errors' => array($element['#parents']),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment