Copied to clipboard

Flag this post as spam?

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


  • Jason Espin 368 posts 1335 karma points
    Dec 11, 2015 @ 11:11
    Jason Espin
    0

    Saving selection - Dropdown prevalue for custom datatype

    Hi all,

    I have created a custom datatype that is essentially a drop-down document type selector. The problem I have is when I select a value and save it, the page does a mini-refresh and the select field is cleared. How do I get angular to reflect the selection I made upon this refresh?

    My code can be found below:

    Package.Manifest

    {
        propertyEditors: [
            {
                alias: "documenttypeselector",
                name: "Document Type Selector",
                hideLabel: false,
                valueType: "STRING",
                editor: {
                    view: "~/App_Plugins/DocumentTypeSelector/PropertyEditors/DocumentTypeSelectorEditor.html?v1.0"
                }
            }
        ],
    
        javascript: [
            "~/App_Plugins/DocumentTypeSelector/PropertyEditors/DocumentTypeSelector.controller.js?v1.0"
        ]
    }
    

    DocumentTypeSelectorEditor.html

    <div ng-controller="DocumentTypeSelector.PropertyEditors.DocumentTypeSelectorController" class="umb-editor">
        <select ng-model="model.value">
            <option ng-repeat="type in documentTypes" value="{{type.Alias}}">{{type.Name}}</option>
        </select>
    </div>
    

    DocumentTypeSelector.controller.js

    angular.module("umbraco")
    .controller("DocumentTypeSelector.PropertyEditors.DocumentTypeSelectorController",
        function ($http, $rootScope, $routeParams, $scope, dialogService, entityResource, editorState, $log, assetsService, iconHelper) {
            $scope.documentTypes = [];
    
            $scope.retreiveDocumentTypes = function () {
                $http.get("/umbraco/backoffice/api/DocumentTypesApi/GetDocumentTypes")
                .success(function (data, status, headers, config) {
                    $scope.documentTypes = data;
                });
            }
    
            $scope.retreiveDocumentTypes();
        }
    );
    
  • Jason Espin 368 posts 1335 karma points
    Dec 11, 2015 @ 11:34
    Jason Espin
    101

    Solved the problem with this:

    <div ng-controller="DocumentTypeSelector.PropertyEditors.DocumentTypeSelectorController" class="umb-editor">
        <select ng-model="model.value">
            <option ng-repeat="type in documentTypes" value="{{type.Alias}}" ng-selected="model.value == type.Alias">{{type.Name}}</option>
        </select>
    </div>
    
  • Ian 178 posts 752 karma points
    Dec 11, 2015 @ 11:56
    Ian
    0

    first double check that model.value does contain a saved value which will re-populate the selectBox. Then I would suggest you might have more luck with the 'ng-options' attribute in angular instead of ng-repeat. so the code might be.

    <select name="selectedType" ng-model="model.value" ng-options="item.Name for item in documentTypes track by item.alias" required>
    

  • Jason Espin 368 posts 1335 karma points
    Dec 11, 2015 @ 15:22
    Jason Espin
    0

    Unfortunately, this didn't work for me so I ended up doing this instead:

    <div ng-controller="Tagliatelle.PropertyEditors.tagliatelleDoctypeSelector" class="umb-editor">
        <select ng-model="model.value">
            <option ng-repeat="type in documentTypes" value="{{type.Alias}}" ng-selected="model.value == type.Alias">{{type.Name}}</option>
        </select>
    </div>
    
Please Sign in or register to post replies

Write your reply to:

Draft