Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Simon Dingley 1472 posts 3429 karma points c-trib
    1 day ago
    Simon Dingley

    Custom Datatype - Accessing data from other config values

    In Umbraco v12 I am trying to create a custom datatype. I have 2 config properties one called items and the other called defaultValue. In angular how can I access the data in items from defaultValue in order to populate a dropdown.

    Here is my controller for the defaultValue config editor:

    angular.module("umbraco").controller("RadioButtonListWithDefault.Controller", ['$scope', '$controller', function ($scope, $controller) {
          // Extend the core CheckboxListController
          angular.extend(this, $controller('Umbraco.PropertyEditors.CheckboxListController', { $scope: $scope }));
          const vm = this;
          vm.model = $scope.model;
          // Initialize items and default from the configuration
          vm.items = vm.model.config.items;
          vm.default = vm.model.config.default;
          // Watch for changes in the items configuration and react accordingly
          $scope.$watch('vm.model.config.items', function (newValue, oldValue) {
              if (newValue !== oldValue) {
                  vm.items = newValue;
          }, true);
          // Watch for changes in the default configuration
          $scope.$watch('vm.model.config.default', function (newValue, oldValue) {
              if (newValue !== oldValue) {
                  vm.default = newValue;
          }, true);
          // Function to update default item options based on the items property
          function updateDefaultItemOptions() {
              if (vm.items) {
                  vm.defaultItemOptions = => ({
                      value: item.value,
                      label: item.value
          // Initialize default item options
          // Ensure model value is set to default if not already set
          if (!vm.model.value && vm.default) {
              vm.model.value = vm.default;
          console.log("Model:", vm.model); 
          console.log("Items:", vm.items); 
          console.log("Default:", vm.default);
          console.log("Default Item Options:", vm.defaultItemOptions); // Debugging line

    $scope.model only gives me access to the current config item model and not the datatype config so that I can access the items.

Please Sign in or register to post replies

Write your reply to: