找回密碼
 立即註冊
搜索
熱搜: 活動 交友 discuz
查看: 536|回復: 1

檔案上傳欄位屬性

[複製鏈接]

257

主題

38

回帖

1138

積分

管理員

積分
1138
發表於 2023-5-25 11:01:32 | 顯示全部樓層 |閱讀模式

upload

Since: Editor 1.5

Single file upload field.
Please note - this property requires the Editor extension for DataTables.

Description

The ability to upload files is an important element in complex forms and data structures. The upload field type provides that ability to Editor by presenting an file upload control to the end user, giving them the option of uploading a single file for the field (the uploadMany field type allows multiple files to be assigned to a single field)

The file upload is performed asynchronously to the main form - i.e. as soon as a file is selected, either via drag-and-drop or a standard file selection control, it is immediately uploaded to the server and the field will take a value that identifies the file (typically this is a database id for a row containing information about the file, but can also be any other identifying data such as a file name). This field value is then submitted as part of the standard form.

The upload field type is supported on the server-side by the Upload class available in Editor's standard libraries (PHP | .NET). Please refer to the documentation for those libraries for how to configure the server-side scripts.

Additionally, an overview of how to configure the upload field types on the client-side is available in the Editor manual. The remaining documentation here is concerned solely with detailing the options available for this field type.

Events

This field type can trigger the following events from the input element (field().input()):

  • upload.editor - Upload complete event - this should be used in place of a change event for this field type. The following parameters are passed in to the event handler:
    1. object event - The event object
    2. Any value - File identifier from the server - normally a primary key value or a file name.

Type

This option can be given in the following type(s):

Options

This field type supports the following options (in addition to the default options):

Methods

This field type does not support any additional methods over the default methods.

Examples

Display an upload field type that displays an image:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
new $.fn.dataTable.Editor( {
  ajax: "php/staff.php",
  table: "#staff",
  fields: [ {
      label: "Image:",
      name: "image",
      type: "upload",
      display: function ( val ) {
          return '<img src="'+table.file( 'files', fileId ).webPath+'"/>';
      }
    },
    // additional fields...
  ]
} );

Disable drag and drop, and enable clearing current value:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
new $.fn.dataTable.Editor( {
  ajax: "php/press.php",
  table: "#press",
  fields: [ {
      label: "Press release PDF:",
      name: "pdf",
      type: "upload",
      display: function ( val ) {
          return table.file( 'files', fileId ).fileName;
      },
      dragDrop: false,
      clearText: 'Remove file'
    },
    // additional fields...
  ]
} );

Listen for an upload event:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var editor = new $.fn.dataTable.Editor( {
  ajax: "php/staff.php",
  table: "#staff",
  fields: [ {
      label: "Image:",
      name: "image",
      type: "upload",
      display: function ( val ) {
          return '<img src="'+table.file( 'files', fileId ).webPath+'"/>';
      }
    },
    // additional fields...
  ]
} );
 
$( editor.field( 'image' ).input() ).on( 'upload.editor'function (e, val) {
  console.log( 'Image field has changed value', val );
} );


257

主題

38

回帖

1138

積分

管理員

積分
1138
 樓主| 發表於 2023-5-25 11:01:41 | 顯示全部樓層

{
                        label: "圖片:",
                        name: "product_category.picture_id",
                        type: "upload",
                        display: function ( file_id ) {
                            return '<img src="'+editor.file( 'product_category_files', file_id ).web_path+'"/>';
                        },
                        clearText: "清除",
                        dragDropText: "請將圖片拖曳至此",
                        noFileText: "沒有檔案",
                        uploadText: "上傳檔案",
                        noImageText: '沒有圖片'
                    }
您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|小黑屋|DoIT 科技論壇

GMT+8, 2025-6-15 21:43 , Processed in 0.029534 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表