Copied to clipboard

Flag this post as spam?

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


  • Daniel Quick 22 posts 74 karma points
    Aug 13, 2015 @ 10:11
    Daniel Quick
    0

    Binding umbraco data to custom macro parameter datatype

    Hello all

    I have been creating some simple macro parameter datatypes using Angular checkbox-list model. they work fine in terms of storing and returning data from the DB, but I cannot get the data to bind to the view control (i.e. checking the checkboxes that have been selected, and are being returned). I have been scratching my head over this one for ages, and would appreciate any help!

    The view:

    <div ng-controller="Eurofins.MultiDivisionPicker">
    <label ng-repeat="division in divisions">
          <input type="checkbox"  checklist-model="selected.divisions" checklist-value="division">{{division.text}}
    </div>
    

    The controller:

    angular.module("umbraco")
        .controller("Eurofins.MultiDivisionPicker",
        function($scope) {
    
                $scope.divisions = [
                      {id: 1, text: 'Apple',   checked: true }, 
                      {id: 2, text: 'Banana',   checked: false },  
                      {id: 3, text: 'Cherry',   checked: false }, 
                      {id: 5, text: 'Damson',   checked: true }, 
                      {id: 6, text: 'Elderberry',   checked: false }, 
                      {id: 7, text: 'Fig,   checked: false }, 
                      {id: 8, text: 'Goji Berry',   checked: false }
                ];
    
    
              //create a blank array to store selected objects.
              $scope.selected = {
                divisions: []
              };
    
              $scope.$on("formSubmitting", function (ev, args) {
                  $scope.model.value = [];
                  $scope.model.value.push($scope.selected);
              });
        });
    

    The manifest:

    {   
    
        propertyEditors: [      
            {
                alias: "Eurofins.MultiDivisionPicker",
                name: "Multi Division Picker",
                  isParameterEditor: true,
                editor: {
                    view: "~/App_Plugins/MultiDivisionPicker/MultiDivisionPicker.html"
                }
            }
        ]
        ,
        javascript: [
            '~/App_Plugins/MultiDivisionPicker/multidivisionpickerA41.controller.js',
            '~/App_Plugins/MultiDivisionPicker/checklist-model.js'
        ]
    }
    

    The checklist-model can be seen here: https://github.com/vitalets/checklist-model/blob/master/checklist-model.js

  • Daniel Quick 22 posts 74 karma points
    Aug 26, 2015 @ 09:18
    Daniel Quick
    0

    Still could do with some assistance on this if anyone has any ideas?

  • Abraham Vijay A 1 post 20 karma points
    Aug 30, 2016 @ 07:20
    Abraham Vijay A
    0

    Hi Daniel,

    The controller should be changed like below to get the values from the DB to the view. The controller:

    angular.module("umbraco") .controller("Eurofins.MultiDivisionPicker", function($scope) {

        $scope.divisions = [
              {id: 1, text: 'Apple',   checked: true }, 
              {id: 2, text: 'Banana',   checked: false },  
              {id: 3, text: 'Cherry',   checked: false }, 
              {id: 5, text: 'Damson',   checked: true }, 
              {id: 6, text: 'Elderberry',   checked: false }, 
              {id: 7, text: 'Fig,   checked: false }, 
              {id: 8, text: 'Goji Berry',   checked: false }
        ];
    
    
      //create a blank array to store selected objects.
      $scope.selected = {
        divisions: **$scope.model.value**
      };
    
      $scope.$on("formSubmitting", function (ev, args) {
          $scope.model.value = [];
          $scope.model.value= $scope.selected.divisions;
      });
    

    });

Please Sign in or register to post replies

Write your reply to:

Draft