0

I'm trying to change the default behavior of Drupal when adding an image through image field on a content type.

When you choose an image to assign to a node, it's not directly uploaded. You also need to click "upload" to display the preview of your image, and this is not really user friendly.

How can I change this (programmatically) to make Drupal start uploading directly the image after choosing the file.

Thank you for help

4

2 回答 2

1

你可以这样做:

(function ($) {
  Drupal.behaviors.autoUpload = {
    attach: function(context, settings) {
      $('.form-item input.form-submit[value=Upload]', context).hide();
      $('.form-item input.form-file', context).change(function() {
        $parent = $(this).closest('.form-item');
        setTimeout(function() {
          if(!$('.error', $parent).length) {
            $('input.form-submit[value=Upload]', $parent).mousedown();
          }
        }, 100);
      });


      $('.form-item input.form-submit[value=Transférer]', context).hide();
      $('.form-item input.form-file', context).change(function() {
        $parent = $(this).closest('.form-item');
        setTimeout(function() {
          if(!$('.error', $parent).length) {
            $('input.form-submit[value=Transférer]', $parent).mousedown();
          }
        }, 100);
      });
    }
  };
})(jQuery);

此解决方案适用于英文和法文浏览器。与AutoUpload模块不同,该模块仅适用于以英文配置的浏览器。注意[value=Upload]/[value=Upload]属性

我发现了一个类似的帖子:

https://drupal.stackexchange.com/questions/31121/how-can-i-automatically-upload-images-on-file-selection-rather-than-pressing-the

这正是我需要的..

于 2012-08-29T14:13:47.073 回答
0

您应该可以使用http://drupal.org/project/imce来满足您的需要。

我不确定图像字段,但是当我遇到这个问题时,我决定让用户在正文中添加图像,因为它对于 durpal 来说是一个更容易的选择 - 在文本中插入图像时,它们会立即显示。

IMCE + filefield 似乎是满足您直接需求的可行选择,他们确实提到了 AJAX 支持。

于 2012-08-29T11:04:35.597 回答