Skip to content

Commit 96cc32a

Browse files
committed
Duplicate section to Mx9 and 10
1 parent 9d116de commit 96cc32a

2 files changed

Lines changed: 146 additions & 0 deletions

File tree

  • content/en/docs/apidocs-mxsdk/apidocs
    • studio-pro-11/pluggable-widgets/pluggable-widgets-client-apis
    • studio-pro-9/pluggable-widgets/pluggable-widgets-client-apis-9

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,79 @@ 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+
#### Formatter Details {#formatter-details}
165+
166+
The `formatter` field on `EditableValue` is defined as follows:
167+
168+
```ts
169+
type ParseResult<T> = { valid: true; value: T } | { valid: false };
170+
171+
interface SimpleFormatter<T> {
172+
format(value: T | undefined): string;
173+
parse(value: string): ParseResult<T>;
174+
}
175+
}
176+
```
177+
178+
You can supply a fully custom formatter using `setFormatter` (the object must implement `format` and `parse`):
179+
180+
```ts
181+
myDecimalAttribute.setFormatter({
182+
format(value: Big | undefined): string {
183+
return value !== undefined ? `$${Number(value).toFixed(2)}` : "";
184+
},
185+
parse(text: string): ParseResult<T> {
186+
const num = Number(text.replace(/[$,]/g, ""));
187+
return isNaN(num) ? { valid: false } : { valid: true, value: new Big(num) };
188+
}
189+
});
190+
191+
```
192+
193+
Call `setFormatter(undefined)` to reset the formatter to the platform default.
194+
195+
**Date/DateTime** attributes have additional capabilities because of `DateTimeFormatter`, which extends `SimpleFormatter<Date>`:
196+
197+
```ts
198+
interface DateTimeFormatter {
199+
type: "datetime";
200+
format(value: Date | undefined): string;
201+
parse(value: string): { valid: true; value: Date } | { valid: false };
202+
withConfig(config: DateTimeFormatterConfig): DateTimeFormatter;
203+
getFormatPlaceholder(): string;
204+
config: DateTimeFormatterConfig;
205+
}
206+
```
207+
208+
You can check `formatter.type` to detect the attribute's data type at runtime and branch your widget logic accordingly:
209+
210+
```ts
211+
if (myAttribute.formatter.type === "datetime") {
212+
// Date-specific formatting logic
213+
} else {
214+
// String, number, enum, or boolean formatting logic
215+
}
216+
```
217+
218+
The following example formats a date attribute using a custom month-year pattern:
219+
220+
```ts
221+
if (myDateAttribute.formatter.type === "datetime") {
222+
const customFormatter = myDateAttribute.formatter.withConfig({
223+
type: "custom",
224+
pattern: "MMMM YYYY"
225+
});
226+
const formatted = customFormatter.format(myDateAttribute.value); // e.g. "March 2026"
227+
}
228+
```
229+
230+
For enumeration and Boolean attributes, `format` converts the raw value into a human-readable caption as configured in Studio Pro:
231+
232+
```ts
233+
// myEnumAttribute is an EditableValue<string>
234+
const caption = myEnumAttribute.formatter.format(myEnumAttribute.value); // e.g. "In Progress"
235+
```
236+
164237
### EditableFileValue {#editable-file-value}
165238

166239
`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:

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,79 @@ There is a way to use more the convenient `displayValue` and `setTextValue` whi
133133

134134
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 attribute is of the Boolean or enumeration [types](/refguide9/attributes/#type).
135135

136+
#### Formatter Details {#formatter-details}
137+
138+
The `formatter` field on `EditableValue` is defined as follows:
139+
140+
```ts
141+
type ParseResult<T> = { valid: true; value: T } | { valid: false };
142+
143+
interface SimpleFormatter<T> {
144+
format(value: T | undefined): string;
145+
parse(value: string): ParseResult<T>;
146+
}
147+
}
148+
```
149+
150+
You can supply a fully custom formatter using `setFormatter` (the object must implement `format` and `parse`):
151+
152+
```ts
153+
myDecimalAttribute.setFormatter({
154+
format(value: Big | undefined): string {
155+
return value !== undefined ? `$${Number(value).toFixed(2)}` : "";
156+
},
157+
parse(text: string): ParseResult<T> {
158+
const num = Number(text.replace(/[$,]/g, ""));
159+
return isNaN(num) ? { valid: false } : { valid: true, value: new Big(num) };
160+
}
161+
});
162+
163+
```
164+
165+
Call `setFormatter(undefined)` to reset the formatter to the platform default.
166+
167+
**Date/DateTime** attributes have additional capabilities because of `DateTimeFormatter`, which extends `SimpleFormatter<Date>`:
168+
169+
```ts
170+
interface DateTimeFormatter {
171+
type: "datetime";
172+
format(value: Date | undefined): string;
173+
parse(value: string): { valid: true; value: Date } | { valid: false };
174+
withConfig(config: DateTimeFormatterConfig): DateTimeFormatter;
175+
getFormatPlaceholder(): string;
176+
config: DateTimeFormatterConfig;
177+
}
178+
```
179+
180+
You can check `formatter.type` to detect the attribute's data type at runtime and branch your widget logic accordingly:
181+
182+
```ts
183+
if (myAttribute.formatter.type === "datetime") {
184+
// Date-specific formatting logic
185+
} else {
186+
// String, number, enum, or boolean formatting logic
187+
}
188+
```
189+
190+
The following example formats a date attribute using a custom month-year pattern:
191+
192+
```ts
193+
if (myDateAttribute.formatter.type === "datetime") {
194+
const customFormatter = myDateAttribute.formatter.withConfig({
195+
type: "custom",
196+
pattern: "MMMM YYYY"
197+
});
198+
const formatted = customFormatter.format(myDateAttribute.value); // e.g. "March 2026"
199+
}
200+
```
201+
202+
For enumeration and Boolean attributes, `format` converts the raw value into a human-readable caption as configured in Studio Pro:
203+
204+
```ts
205+
// myEnumAttribute is an EditableValue<string>
206+
const caption = myEnumAttribute.formatter.format(myEnumAttribute.value); // e.g. "In Progress"
207+
```
208+
136209
### ModifiableValue {#modifiable-value}
137210

138211
`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-9/#association), and is defined as follows:

0 commit comments

Comments
 (0)