Copied to clipboard

Flag this post as spam?

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


  • Isaiah Pellarp 9 posts 29 karma points
    1 week ago
    Isaiah Pellarp
    0

    Setting a min and max value of required items for a macro multi url custom property

    Hi,

    I have been making a custom property for a social media macro block where I want to have a multi url picker that has a minimum requirement of 2 url and a maximum of 4 urls and I have gotten it to work to the point where I can add urls, but there is no limit or any minimum requirement since I cant seem to get the config to work as I want it to.

    Here is my manifest code:

    "javascript": [
    "~/App_Plugins/**/MacroUrlPickerMinMax/MacroUrlPickerMinMax.js",
        ],
    "propertyEditors": [
    {
            "alias": "TT.MacroUrlPickMinMax",
            "name": "Macro multi url picker MinMax",
            "isParameterEditor": true,
            "editor": {
                "view": "~/App_Plugins/**/MacroUrlPickerMinMax/macrourlpickerminmax.html"
            },
            "prevalues": {
                "fields": [
                    {
                        "label": "max Count",
                        "description": "set max allowed",
                        "key": "maxCount",
                        "view": "boolean",
                        "defaultConfig": {
                            "default":  true,
                            "maxCount": 2
                        }
                    }
                ]
            }
        }
    ]
    

    The only error I seem to be getting in inspect mode from console is:

    TypeError: Cannot read property 'minCount' of undefined at MacroUrlPickerMinMax.js?cdv=1806545781:47 at Scope.$digest (angular.js?cdv=1806545781:19208) at ChildScope.$apply (angular.js?cdv=1806545781:19568) at HTMLButtonElement.

    This is referencing to a part in my .js file:

    $scope.$on("formSubmitting", function () {
        $scope.model.value = $scope.renderModel;
    });
    
    $scope.$watch(
        function () {
            return $scope.renderModel.length;
        },
        function () {
            //Validate!
            if ($scope.model.config && $scope.model.config.minNumber && parseInt($scope.model.config.minNumber) > $scope.renderModel.length) {
                $scope.multiUrlPickerForm.minCount.$setValidity("minCount", false);
            }
            else {
                $scope.multiUrlPickerForm.minCount.$setValidity("minCount", true);
            }
    
            if ($scope.model.config && $scope.model.config.maxNumber && parseInt($scope.model.config.maxNumber) < $scope.renderModel.length) {
                $scope.multiUrlPickerForm.maxCount.$setValidity("maxCount", false);
            }
            else {
                $scope.multiUrlPickerForm.maxCount.$setValidity("maxCount", true);
            }
            $scope.sortableOptions.disabled = $scope.renderModel.length === 1;
        }
    );
    

    When looking in the backoffice section where I edit my macro properties the console shows no config or default config for some reason:

    Console

    Been at this for 6 hours now and still am no closer to making this work. The end goal for this is to be able to limit how many items are needed and how many items are allowed to be added by an editor, if anybody has any advice it would be much appreciated! :)

  • Marc Goodson 1419 posts 9552 karma points MVP 5x c-trib
    1 week ago
    Marc Goodson
    0

    Hi Isaiah

    I have a feeling it's to do with PreValues and the DefaultConfig setting for your custom editor.

    PreValues are used to provide a configuration option for the editor when it is viewed as a DataType

    And can be read inside the angularJS controller from $scope.model.config.aliasOfPreValue

    DefaultConfig: is an option to provide values for those PreValues when the editor is used in a situation where you can't set them via the backoffice UI, eg in a Macro Parameter etc

    Anyway your custom Url Picker Package Manifest defines only 1 PreValue called 'maxCount'

    It defined as a 'boolean' via it's view, and then you are trying to set the defaultconfiguration - for this boolean property - when there is a UI for someone to provide the value (eg in a new DataType) - but instead of setting a default boolean value for this option, you are setting two properties, one called 'Default' and one called 'maxCount' and the 'Boolean' view for a checkbox isn't going to know how to interpret that!

    But maybe you are not trying to set the defaultconfig value of the configuration option?

    If you are instead trying to set the defaultconfig for the editor as a whole, then your defaultConfig: definition needs to be outside of the preValues configuration:

    Have a look at this example in the docs;

    https://our.umbraco.com/Documentation/Extending/Macro-Parameter-Editors/#using-defaultconfig

    You can see the DefaultConfig for the ImagePosition is 'outside' of the preValues configuration...

    I think you'll need to have a PreValue field entry for each property you want people to be able to configure or that you want to set in the editor's default configuration.

    The built in Multi Url Picker can be made to work as a Macro Parameter, 'as of' V8.7... an example of the configuration to make it work, is in this PR that fixed a bug that made it possible:

    https://github.com/umbraco/Umbraco-CMS/pull/8144

    regards

    marc

Please Sign in or register to post replies

Write your reply to:

Draft