-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Umbraco.Decimal Property Editor: Add Default value (closes #21787) #23015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,13 @@ export const manifests: Array<UmbExtensionManifest> = [ | |
| propertyEditorUiAlias: 'Umb.PropertyEditorUi.Decimal', | ||
| config: [{ alias: 'step', value: '0.000001' }], | ||
| }, | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps move this so it comes after the step setting? Seems like min and max (and arguably step) should go together as they are part of the same process of considering what valid values are. |
||
| alias: 'defaultValue', | ||
|
nielslyngsoe marked this conversation as resolved.
|
||
| label: 'Default value', | ||
| description: 'Enter the default value to use when a new property is created', | ||
| propertyEditorUiAlias: 'Umb.PropertyEditorUi.Decimal', | ||
| config: [{ alias: 'step', value: '0.000001' }], | ||
| }, | ||
| { | ||
| alias: 'max', | ||
| label: 'Maximum', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,26 @@ | |
| implements UmbPropertyValuePreset<UmbDecimalPropertyEditorUiValue, UmbPropertyEditorConfig> | ||
| { | ||
| async processValue(value: undefined | UmbDecimalPropertyEditorUiValue, config: UmbPropertyEditorConfig) { | ||
| const min = Number(config.find((x) => x.alias === 'min')?.value ?? 0); | ||
| const minVerified = isNaN(min) ? 0 : min; | ||
| const defaultValue = this.#parseConfiguredNumber(config, 'defaultValue'); | ||
| if (defaultValue !== undefined) { | ||
| return value !== undefined ? value : defaultValue; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I note you can configure a default value that's outside of the min and max and therefore will be immediately invalid. We could look to clamp it, so if they default is lower than the min it'll use the min and if greater than the max it'll use the max. But I'm not sure it's necessary. When it comes to data type configuration validation we don't currently enforce that these settings are internally correct, and rely on the developer to get it right for their editors. So no action here I feel, just noting. |
||
| } | ||
|
|
||
| return value !== undefined ? value : minVerified; | ||
| const min = this.#parseConfiguredNumber(config, 'min') ?? 0; | ||
| return value !== undefined ? value : min; | ||
| } | ||
|
|
||
| destroy(): void {} | ||
|
|
||
| #parseConfiguredNumber(config: UmbPropertyEditorConfig, alias: string): number | undefined { | ||
| const rawValue = config.find((x) => x.alias === alias)?.value; | ||
| if (rawValue === undefined || rawValue === null || rawValue === '') { | ||
|
Check warning on line 22 in src/Umbraco.Web.UI.Client/src/packages/property-editors/number/decimal-property-value-preset.ts
|
||
| return undefined; | ||
| } | ||
|
|
||
| const parsedValue = Number(rawValue); | ||
| return Number.isFinite(parsedValue) ? parsedValue : undefined; | ||
| } | ||
| } | ||
|
|
||
| export { UmbDecimalPropertyValuePreset as api }; | ||
Uh oh!
There was an error while loading. Please reload this page.