Skip to content

Commit 75b270a

Browse files
committed
Update Image and File properties, add EditableImageValue, EditableFileValue sections
1 parent cc634ba commit 75b270a

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/pluggable-widgets/pluggable-widgets-client-apis/_index.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,51 @@ There is a way to use more the convenient `displayValue` and `setTextValue` whi
161161

162162
The optional field `universe` is used to indicate the set of all possible values that can be passed to a `setValue` if a set is limited. Currently, `universe` is provided only when the edited value is of the Boolean or enumeration [types](/refguide/attributes/#type).
163163

164+
### EditableFileValue {#editable-file-value}
165+
166+
`EditableFileValue` is used to represent file values, that can be changed by a pluggable widget client component and is passed only to [file](/apidocs-mxsdk/apidocs/pluggable-widgets-property-types/#file). It is defined as follows:
167+
168+
```ts
169+
export interface EditableFileValue<T = FileValue> {
170+
readonly status: ValueStatus;
171+
readonly readOnly: boolean;
172+
173+
readonly validation: Option<string>;
174+
setValidator: (validator?: (value: Option<T>) => Option<string>) => void;
175+
176+
readonly value: Option<T>;
177+
setValue: (value: Option<T>) => void;
178+
}
179+
```
180+
181+
Member `status` is similar to one exposed for `DynamicValue`. It indicates if the value's loading has finished and if loading was successful. Similarly to `DynamicValue`, `EditableFileValue` keeps returning the previous `value` when `status` changes from `Available` to `Loading` to help a widget avoid flickering.
182+
183+
The flag `readOnly` indicates whether a value can actually be edited. The `readOnly` flag is always true when a `status` is not `ValueStatus.Available`. Any attempt to edit a value set to read-only will have no affect and incur a debug-level warning message.
184+
185+
The value can be read from the `value` field and modified using `setValue` function. Note that `setValue` returns nothing and does not guarantee that the value is changed synchronously. But when a change is propagated, a component receives a new prop reflecting the change.
186+
187+
When setting a value, a new value might not satisfy certain validation rules — for example when a file is selected and the new value is bigger than the underlying file allows, or the file type is not allowed. In this case, your change will affect only `value` received through a prop. Your change will not be propagated to an object and will not be visible outside of youAllowUpload (Optional)
188+
189+
This component. The component will also receive a validation error text through the `validation` field of `EditableFileValue`.
190+
191+
It is possible for a component to extend the defined set of validation rules. A new validator — a function that checks a passed value and returns a validation message string if any — can be provided through the `setValidator` function. A component can have only a single custom validator. The Mendix Platform ensures that custom validators are run whenever necessary, for example when a page is being saved by an end-user. It is best practice to call `setValidator` early in a component's lifecycle — specifically in the [componentDidMount](https://en.reactjs.org/docs/react-component.html#componentdidmount) function.
192+
193+
### EditableImageValue {#editable-image-value}
194+
195+
`EditableImageValue` is used to represent image values, that can be changed by a pluggable widget client component and is passed only to [image](/apidocs-mxsdk/apidocs/pluggable-widgets-property-types/#image). It acts as an extension of [EditableFileValue](#editable-file-value) it is defined as follows:
196+
197+
```ts
198+
export interface EditableImageValue<T extends ImageValue> extends EditableFileValue<T> {
199+
setThumbnailSize: (width: Option<number>, height: Option<number>) => void;
200+
}
201+
```
202+
203+
`EditableImageValue` provides upload capabilities to [`ImageValue`](#imagevalue), similarly to how [`EditableFileValue`](#editable-file-value) for [`FileValue`](#filevalue). Also it adds `setThumbnailSize` method which enables a component to request the Mendix Platform to return an image with specific dimensions. The Mendix Platform will take care of resizing the image while keeping the aspect ratio intact. When a thumbnail size is set, the `value` field of `EditableImageValue` will contain a resized image. When a thumbnail size is not set, the `value` field will contain an original image.
204+
205+
{{% alert color="warning" %}}
206+
`EditableImageValue` does not support `NativeImage`.
207+
{{% /alert %}}
208+
164209
### ModifiableValue {#modifiable-value}
165210

166211
`ModifiableValue` is used to represent values that can be changed by a pluggable widget client component. It is passed only to [association properties](/apidocs-mxsdk/apidocs/pluggable-widgets-property-types/#association), and is defined as follows:

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/pluggable-widgets/pluggable-widgets-property-types.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ The common structure of a property definition is as follows:
2626

2727
This defines the prop `key` in the client component props which are supplied to the widget client component. Each property must have a unique `key` which can contain letters of all cases, digits, or underscores. However, a `key` attribute cannot *start* with a digit.
2828

29+
#### AllowUpload (Optional) {#allow-upload}
30+
31+
This optional attribute is only applicable for properties of type [file](#file) and [image](#image) and has a default value of `false`. By setting this attribute to `true` a user can use the upload capabilities by passing `EditableFileValue<FileValue>` and `EditableImageValue<ImageValue>` as props to a client component. Using `false` is used for legacy `DynamicValue<File>` and `DynamicValue<ImageValue>`.
32+
33+
{{% alert color="warning" %}}
34+
Optional attribute `allowUpload` will be deprecated as of Mx 12. After Mx 12 such `file` and `image` will have by default editing capabilities and users will not be able to use the legacy behavior.
35+
36+
After Mx 12, the attribute won't be taken into account during the property evaluation, and legasy functionality won't be available.
37+
{{% /alert %}}
38+
2939
#### Type (required)
3040

3141
This defines a property's type. A `type` must be one of the following:
@@ -257,26 +267,29 @@ Then the Studio Pro UI for the component appears like this:
257267

258268
### Image {#image}
259269

260-
Image allows a user to configure a static image from an [image collection](/refguide/image-collection/). It also allows a user to configure an image from an object that is a specialization of **System.Image**. It is passed as an `DynamicValue<ImageValue>` prop to a client component (for more information, see the [ImageValue](/apidocs-mxsdk/apidocs/pluggable-widgets-client-apis/#imagevalue) section of *Client APIs Available to Pluggable Widgets*). See the [Images Reference Guide](/refguide/images/) for more information about supported image formats.
270+
Image allows a user to configure an image from an object that is a specialization of **System.Image**. It is passed as an [`EditableImageValue<ImageValue>`](/apidocs-mxsdk/apidocs/pluggable-widgets-client-apis/#editable-image-value) prop to a client component. See the [Images Reference Guide](/refguide/images/) for more information about supported image formats.
271+
272+
The user can use the optional attribute [`allowUpload`](#allow-upload) with default value `false` to use the legasy [`Dynamic<FileValue>`](/apidocs-mxsdk/apidocs/pluggable-widgets-client-apis/#filevalue) prop. Beware of behavioral differences based on the `allowUpload` attribute.
261273

262274
{{% alert color="warning" %}}
263-
GIF images are not supported in native mobile apps on Android devices.
275+
Optional attribute `allowUpload` will be deprecated as of Mx 12. After Mx 12 such `image` will have by default editing capabilities and users will not be able to use the legacy behavior.
264276
{{% /alert %}}
265277

266278
#### XML Attributes
267279

268-
| Attribute | Required | Attribute Type | Description |
269-
|------------|----------|----------------|-----------------------------------------------------------------------|
270-
| `type` | Yes | String | Must be `image` |
271-
| `key` | Yes | String | See [key](#key) |
272-
| `required` | No | Boolean | Whether the property must be specified by the user, `true` by default |
280+
| Attribute | Required | Attribute Type | Description |
281+
|---------------|----------|----------------|-----------------------------------------------------------------------|
282+
| `type` | Yes | String | Must be `image` |
283+
| `key` | Yes | String | See [key](#key) |
284+
| `required` | No | Boolean | Whether the property must be specified by the user, `true` by default |
285+
| `allowUpload` | No | Boolean | See [allowUpload](#allow-upload) |
273286

274287
#### Studio Pro UI
275288

276289
When the component is defined as follows:
277290

278291
```xml
279-
<property key="bgImage" type="image" required="false">
292+
<property key="bgImage" type="image" required="false" allowUpload="true" >
280293
<caption>Background Image</caption>
281294
<description>Image shown blurred in a background</description>
282295
</property>
@@ -699,22 +712,29 @@ Then the Studio Pro UI for the property appears like this:
699712

700713
### File {#file}
701714

702-
The file property type allows a user to configure a file from an object that is a specialization of **System.File**. It is passed as a [`DynamicValue<FileValue>`](/apidocs-mxsdk/apidocs/pluggable-widgets-client-apis/#filevalue) prop to a client component.
715+
The file property type allows a user to configure and edit a file from and to an object that is a specialization of **System.File**. It is passed as a [`EditableFileValue<FileValue>`](/apidocs-mxsdk/apidocs/pluggable-widgets-client-apis/#editable-file-value) prop to a client component.
716+
717+
The user can use the optional attribute [`allowUpload`](#allow-upload) with default value `false` to use the legasy [`Dynamic<FileValue>`](/apidocs-mxsdk/apidocs/pluggable-widgets-client-apis/#filevalue) prop. Beware of behavioral differences based on the `allowUpload` attribute.
718+
719+
{{% alert color="warning" %}}
720+
Optional attribute `allowUpload` will be deprecated as of Mx 12. After Mx 12 such `file` will have by default editing capabilities and users will not be able to use the legacy behavior.
721+
{{% /alert %}}
703722

704723
#### XML Attributes
705724

706-
| Attribute | Required | Attribute Type | Description |
707-
|-----------|----------|----------------|-----------------|
708-
| `type` | Yes | String | Must be `file` |
709-
| `key` | Yes | String | See [key](#key) |
725+
| Attribute | Required | Attribute Type | Description |
726+
|---------------|----------|----------------|----------------------------------|
727+
| `type` | Yes | String | Must be `file` |
728+
| `key` | Yes | String | See [key](#key) |
729+
| `allowUpload` | No | Boolean | See [allowUpload](#allow-upload) |
710730

711731
#### Studio Pro UI
712732

713733
When the property is defined as follows:
714734

715735
```xml
716736

717-
<property key="file" type="file" required="false">
737+
<property key="file" type="file" required="false" allowUpload="true">
718738
<caption>File</caption>
719739
<description>Sample text file</description>
720740
</property>

0 commit comments

Comments
 (0)