Skip to content
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

Use data type configuration to determine default value for empty toggle and slider property values #17854

Merged

Conversation

AndyButland
Copy link
Contributor

@AndyButland AndyButland commented Dec 20, 2024

Prerequisites

  • I have added steps to test this contribution in the description below

Fixes #17833, tracked under AB 45702 (internal HQ tracker)

Also Fixes #17099, tracked under AB 47510

Description

Reported issue: For toggle properties set to the initial value of true, this is not working. The value is stored as false even though it is displayed as “on” in the UI.

Background: If the user does not interact with a Property Editor, we do not store anything.
This is how the Client works as of v.14, and this plays well with the fact that we do not render Property Editors that the user haven't navigated to, meaning we do not guarantee that the Property Editor UI would be available to set an initial(default) value.
In other words, Default Values should be set by the server.

Reproduction:

  • Create two data types based on the "Toggle" property editor named "Toggle 1" and "Toggle 2".
  • For one set the "Initial state" value to "on", for the other leave it "off".
  • Add the two data types to a document type and render in a template like the following:
@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.HomePage>
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
@{
  Layout = null;
}

<ul>
  <li>Setting 1: @Model.Toggle1</li>
  <li>Setting 2: @Model.Toggle2</li>
</ul>
  • Create a content item based on the document type, note that one toggle will be on and one off as expected.
  • Save and publish the document type without touching the toggles.
  • Render the page and note that both toggle values are false.

With this PR I've added a check for null values in the property value converter, when, if found, the default value from the data type configuration will be used.

To Test:

  • Follow the reproduction steps described and note that with the PR applied that the expected values are displayed.
  • Edit the content, setting the toggle values explicitly, and confirm you again see the expected values.
  • Repeat for the slider.

@nielslyngsoe
Copy link
Member

Fixes #17833

@AndyButland AndyButland changed the title Use data type configuration to determine default value for empty toggle property values. Use data type configuration to determine default value for empty toggle and slider property values Jan 3, 2025
@AndyButland
Copy link
Contributor Author

I found a similar issue raised for the slider property editor, so have fixed that in a similar way as part of this PR.

…peInfoResolver for data type configuration so we can re-use the existing ConfigurationField attributes.
Copy link
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and tests good, I did a very minor cleanup renaming a variable, hope that's okay 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants