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 19 posts 73 karma points
    Feb 15, 2021 @ 15:27
    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 2128 posts 14220 karma points MVP 8x c-trib
    Feb 21, 2021 @ 09:59
    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

  • Isaiah Pellarp 19 posts 73 karma points
    Mar 01, 2021 @ 07:35
    Isaiah Pellarp
    0

    Hi Mark,

    Than you for your lenghtly reply and sorry for not responding earlier! I managed to make it appear as a property to be used for macros with a min / max value set (would just allow for checkboxes to be ticked if you wanted one or the other with a hard coded value). Although I could never get it to actually enforce the min or max value with any validation or anything..so atm I think im more confused as to where that is controlled and how.

    Thank you for your help!

  • Marc Goodson 2128 posts 14220 karma points MVP 8x c-trib
    Mar 01, 2021 @ 18:40
    Marc Goodson
    0

    HI Isaiah

    So, what did you end up with as your manifest file?

    As the short version of what I'm explaining above based on the manifest file you had original posted - is you have defaultConfig in the wrong place! :-P

    so wondering if you worked that out, and it's still not working, or whether that's not clear from my overly verbose explanation!

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft