Copied to clipboard

Flag this post as spam?

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


  • Frans de Jong 550 posts 1862 karma points MVP 4x c-trib
    May 02, 2017 @ 19:32
    Frans de Jong
    0

    Custom property editor initial state of radio list

    I need a stylesheet picker so I thought I'd build it my self :P

    This is my first property editor and everything works as it should except for the initial state.

    What I have now:

    Controller:

    angular.module("umbraco").controller("Webwonders.StylesheetPicker",
        function ($scope, stylesheetResource) {
            if (!$scope.stylesheets) {
                $scope.stylesheets = [];
            }
    
            stylesheetResource.getAll().then(function (stylesheets) {
                var emptyRadio = { name: "Geen stylesheet", path: ""};
                $scope.stylesheets = stylesheets;
                $scope.stylesheets.splice(0, 0, emptyRadio);
            });
    
            $scope.isSelected = function (stylesheet) {
                stylesheet.isSelected = $scope.model.value.name == stylesheet.name;
                return stylesheet.isSelected;
            };
    
            $scope.selectStylesheet = function (stylesheet) {
                $scope.model.value = stylesheet;
            };
        });
    

    View:

    <div ng-controller="Webwonders.StylesheetPicker" >
        <div ng-repeat="css in stylesheets">
            <label>
                <input type="radio" name="stylesheets"
                        ng-checked="isSelected(css)"
                        ng-model="model.value"
                        ng-change="selectStylesheet(css)" />
                {{css.name}}
            </label>
        </div>
        <p>{{model.value}}</p>
    </div>
    

    So model.value always has the correct value but all the radios are empty onload.

    Any clues?

  • Frans de Jong 550 posts 1862 karma points MVP 4x c-trib
    May 03, 2017 @ 13:23
    Frans de Jong
    0

    Ive put a console.log showing the stylesheets after $scope.stylesheets.splice(0, 0, emptyRadio); in the stylesheetResource.getAll() method.

    It looks like its only a visual problem because the correct isSelected is set to true.

    enter image description here

    After I click on a radio the problem is solved and the radios show the correct state.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

    Continue discussion

Please Sign in or register to post replies