Class: AttachmentEntryProxy¶
AttachmentEntryProxy is a developer-facing interface that provides access to an item of the Attachment control in the OnPress event. In addition, it provides access to the IAttachmentEntryProxy interface.
example
// Basic usage inside an Attachment OnPress rule
export default function AttachmentOnPress(context) {
// context is an AttachmentEntryProxy instance
const attachmentEntryProxy = context;
const attachmentValue = attachmentEntryProxy.getValue();
// Log the urlString if available
if (attachmentValue?.urlString) {
console.log('Pressed attachment file:', attachmentValue.urlString);
} else {
console.log('No attachment URL available.');
}
// Open the attachment
attachmentEntryProxy.open();
}
Hierarchy¶
-
AttachmentEntryProxy
Implements¶
Summary¶
Constructors¶
Properties¶
Class Properties¶
Inherited Properties¶
Accessors¶
Class Accessors¶
Currently none in this class.
Inherited Accessors¶
Methods¶
Class Methods¶
Inherited Methods¶
Constructors¶
constructor¶
+ new AttachmentEntryProxy(context: IContext): AttachmentEntryProxy
Overrides ElementProxy.constructor
Parameters:
| Name | Type |
|---|---|
context |
IContext |
Returns: AttachmentEntryProxy
Properties¶
Protected _row¶
• _row: any
Methods¶
createAttachmentEntry¶
▸ createAttachmentEntry(attachmentPath: string, entitySet: string, property: string, readLink: string, service: string, encodeURI: boolean): any
Implementation of IAttachmentEntryProxy
Create an object for attachment entry Note: This function is for iOS & Android only
example
// Create and append a new attachment entry to the parent control
const attachmentEntryProxy = context;
const parent = attachmentEntryProxy.getParent();
const imagePath = '/path/to/image.jpg';
const readLink = context.getReadLink();
const newEntry = attachmentEntryProxy.createAttachmentEntry(imagePath, 'BookImages', 'image', readLink, '/MDKApp/Services/Bookshop.service');
if (newEntry) {
const list = parent.getValue() || [];
list.push(newEntry);
parent.setValue(list, true);
}
// Disable URI encoding (encodeURI = false)
const absolutePath = '/storage/documents/My Image.jpg'; // absolute path without file:// prefix
const anotherEntry = attachmentEntryProxy.createAttachmentEntry(absolutePath, 'BookImages', 'image', readLink, '/MDKApp/Services/Bookshop.service', false);
if (anotherEntry) {
console.log('Entry created with raw path:', anotherEntry); // logs the entry created without URI encoding
}
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
attachmentPath |
string | - | the path for the attachment file |
entitySet |
string | - | entity set name |
property |
string | - | the property of the entity set |
readLink |
string | - | readlink string |
service |
string | - | service name |
encodeURI |
boolean | true | whether to prefix the path with 'file://' if it is not already using another URI protocol, default value is true |
Returns: any
an object with all information for the attachment entry or undefined if the attachment is invalid
getParent¶
▸ getParent(): IAttachmentFormCellProxy
Implementation of IAttachmentEntryProxy
Overrides ElementProxy.getParent
This method returns AttachmentFormCell proxy
example
// Access the parent AttachmentFormCell to manipulate the whole list
const attachmentEntryProxy = context;
const parent = attachmentEntryProxy.getParent();
// Clear all attachments from the parent control
parent.setValue([], true);
console.log('All attachments cleared.');
Returns: IAttachmentFormCellProxy
getValue¶
▸ getValue(): any
Implementation of IAttachmentEntryProxy
Get item value (Read-Only). The value is in accordance with the interface IAttachment definition.
example
// Read the attachment value when an item is pressed
const attachmentEntryProxy = context;
const value = attachmentEntryProxy.getValue();
console.log('Attachment MIME type:', value.contentType);
Returns: any
the value of the item
open¶
▸ open(): any
Implementation of IAttachmentEntryProxy
Open the attachment
example
// Programmatically open the pressed attachment
const attachmentEntryProxy = context;
attachmentEntryProxy.open();
Returns: any
setValue¶
▸ setValue(value: any, notify?: boolean): any
Implementation of IAttachmentEntryProxy
Set the new value in the item. The value should be generated from: FormCellControlProxy.createAttachmentEntry() or AttachmentEntryProxy.createAttachmentEntry()
example
// Replace an existing attachment with a new one and trigger the parent's OnValueChange event
const attachmentEntryProxy = context;
const newImagePath = '/path/to/newImage.jpg';
const readLink = context.getReadLink();
// Create a new attachment entry object
const newAttachment = attachmentEntryProxy.createAttachmentEntry(newImagePath, 'BookImages', 'image', readLink, '/MDKApp/Services/Bookshop.service');
if (newAttachment) {
// Replace the current entry's value with the new one
attachmentEntryProxy.setValue(newAttachment, true);
}
Parameters:
| Name | Type | Description |
|---|---|---|
value |
any | value to be set |
notify? |
boolean | whether to triggers the OnValueChange event on the parent control |
Returns: any
this - allows chaining