Class

Attachment

kiss.ui.Attachment(config)

The Attachment derives from Component.

It allow to manipulate files:

  • upload files
  • preview uploaded files
  • delete files
Constructor

# new Attachment(config)

Its a Custom Web Component. Do not use the constructor directly with the new keyword. Instead, use one of the 3 following methods:

Create the Web Component and call its init method:

const myAttachment = document.createElement("a-attachment").init(config)

Or use the shorthand for it:

const myAttachment = createAttachment({
 label: "My uploaded files",
 multiple: true
})

myAttachment.render()

Or directly declare the config inside a container component:

const myPanel = createPanel({
  title: "My panel",
  items: [
      {
         type: "attachment",
         label: "My uploaded files",
         multiple: true
      }
  ]
})
myPanel.render()
Parameters:
Name Type Attributes Description
config object
label string <optional>
buttonText string <optional>

Text of the upload button. Defaults to "attach files"

value Array.<object> <optional>

Default value

layout string <optional>

"" (default) | "thumbnails" | "thumbnails-large"

allowLayout boolean <optional>

true (default) to display the buttons to change the layout

multiple boolean <optional>

TODO: true to enable multi-select

readOnly boolean <optional>
disabled boolean <optional>

TODO

required boolean <optional>

TODO

margin string <optional>
padding string <optional>
labelFontSize string <optional>

Any valid CSS value

labelFontWeight string <optional>

Any valid CSS value

labelColor string <optional>

Any valid CSS value

ACL string <optional>

The access control list for the uploaded files. "private" or "public". Defaults to "private"

maxSize number <optional>

The maximum size of the file to upload, in bytes. Defaults to 0 (no limit).

record object <optional>

The record to bind the field to. This will automatically update the record when the field value changes, and the field will listen to database changes on the record.

View Source client/ui/fields/attachment.js, line 47

this

Generated markup

The field is a composition of various elements:

  • a span for the field label
  • a span for the button to upload new files, which includes a span for the button icon
  • a div to display the gallery of thumbnails
<a-attachment class="a-attachment">
  <span class="field-label"></span>
  <span class="a-button attachment-button field-upload-button">
      <span class="fas fa-paperclip attachment-icon"></span> Attach files
  </span>
  <div class="field-attachment-gallery">
  </div>
</a-attachment>

Methods

# clearValue()

Clear the field value

View Source client/ui/fields/attachment.js, line 368

this

# getLabel() → {string}

Get the field label

View Source client/ui/fields/attachment.js, line 414

string

# getValue() → {Array.<string>}

Get the field value

View Source client/ui/fields/attachment.js, line 394

  • The field value
Array.<string>

# renderAs(mode)

Render the attachments in different modes:

  • list
  • thumbnails
  • large thumbnails
Parameters:
Name Type Description
mode string

"list" | "thumbnails" | "thumbnails-large"

View Source client/ui/fields/attachment.js, line 196

# resetValue()

Reset the field value

View Source client/ui/fields/attachment.js, line 403

this

# setLabel(newLabel)

Set the field label

Parameters:
Name Type Description
newLabel string

View Source client/ui/fields/attachment.js, line 424

this

# setValue(newValues, rawUpdateopt)

Set the field value

Parameters:
Name Type Attributes Description
newValues Array.<object>

The new field value

rawUpdate boolean <optional>

If true, it doesn't update the associated record and doesn't trigger "change" event

View Source client/ui/fields/attachment.js, line 340

this

# showUploadWindow(configopt)

Display the upload window of the attachment field

Parameters:
Name Type Attributes Description
config object <optional>

Configuration object

ACL string <optional>

The access control list for the uploaded files. "private" or "public". Defaults to "private"

maxSize number <optional>

The maximum size of the file to upload, in bytes. Defaults to 0 (no limit)

View Source client/ui/fields/attachment.js, line 254

# validate() → {boolean}

Validate the field (always true because Attachment fields can't have wrong values)

View Source client/ui/fields/attachment.js, line 437

boolean
new Attachment

Methods