I'm trying to reuse a custom datatype in my custom section...
I've been following a few different tutorials and have have successfully gotten my user control rendering with the correct prevalues. However, I cannot figure out how to set the dropdown value when I load an existing record.
i'm initializing the datatype control model:
angular.module("umbraco").controller("BoardMember.editController", function ($scope, $routeParams, boardMemberResource, notificationsService, navigationService, entityResource, dataTypeResource) {
...
$scope.board_titles = []; // { model: {} };
var bt_model = {
name: "board_title",
alias: "board_title",
label: "Board Position",
view: "dropdown",
description: 'Enter the position on the board this member currently holds.',
config: {
items: [],
multiple: false,
hideLabel: true
},
hideLabel: true,
value: "",
existingValue: null,
hasValue: false
};
One thing I noticed, when the form is rendered the dropdown control is given the name "dropdownlist" from the view, not my alias...some of my model properties have been created as a part of my testing...
I had to create a custom property editor essentially. I copied the dropdown.html from Umbraco/views/propertyeditors/ as the foundation for my custom dropdown editor:
<div ng-controller="BoardMember.BoardPositionDropdownController" ng-switch="model.config.multiple">
<select name="dropDownList{{model.alias}}"
class="umb-editor umb-dropdown"
ng-switch-default
ng-model="model.value"
ng-options="item.id as item.value for item in model.config.items track by item.value"
ng-change="changed()">
</select>
<span ng-model="model.value"></span><span ng-bind="model.value"></span>
</div>
Note the select name property: I tacked on my property model.alias to avoid any DOM conflicts that might occur (this was an edit from the Umbraco view).
I also added the "..track by..." statement to the ng-options.
Now my dropdown is loading the prevalues from my custom datatype I created in the Developer / datatypes area of the backoffice... and my saved record in the database is loading the correct value on the edit page...However...when I change or select a new option, the select control clears itself, the list is still there, but no values can be actually selected...
I put a function on ng-change and write $scope.model to console and it's now undefined...
So after a bit more debugging I had to add a $watch to the controller for my custom view:
angular.module("umbraco")
.controller("BoardMember.BoardPositionDropdownController",
function ($scope) {
var _mod = this;
var _scp = $scope;
$scope.$watch('model.value', function (newVal, oldVal, scope) {
scope.model.value = (typeof newVal === "undefined") ? oldVal : newVal;
});
});
So now it loads my saved value, and I can selected the new value if I want to edit it... BUT NOW... I can't find the new value in scope to pass to my parent controller scope...
Custom Section - Reuse Datatype dropdownlist
I'm trying to reuse a custom datatype in my custom section... I've been following a few different tutorials and have have successfully gotten my user control rendering with the correct prevalues. However, I cannot figure out how to set the dropdown value when I load an existing record.
i'm initializing the datatype control model:
... Then if a record is being edited:
... my custom view for the section looks like this:
Is there an "easier" way or a "more appropriate" way to accomplish this task (reusing custom datatypes in sections)?
One thing I noticed, when the form is rendered the dropdown control is given the name "dropdownlist" from the view, not my alias...some of my model properties have been created as a part of my testing...
This is a screen shot of whats being rendered...
So I've figured a few things out... The model="model.value" needs to be an object:
I had to create a custom property editor essentially. I copied the dropdown.html from Umbraco/views/propertyeditors/ as the foundation for my custom dropdown editor:
Note the select name property: I tacked on my property model.alias to avoid any DOM conflicts that might occur (this was an edit from the Umbraco view).
I also added the "..track by..." statement to the ng-options.
Now my dropdown is loading the prevalues from my custom datatype I created in the Developer / datatypes area of the backoffice... and my saved record in the database is loading the correct value on the edit page...However...when I change or select a new option, the select control clears itself, the list is still there, but no values can be actually selected...
I put a function on ng-change and write $scope.model to console and it's now undefined...
So after a bit more debugging I had to add a $watch to the controller for my custom view:
So now it loads my saved value, and I can selected the new value if I want to edit it... BUT NOW... I can't find the new value in scope to pass to my parent controller scope...
well... I solved the final issue of not being able to save the selected value upon editing...
Changed to (removed "item.id as"):
is working on a reply...