Fixes radio button editor
This commit is contained in:
@@ -3,28 +3,33 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro
|
||||
|
||||
function init() {
|
||||
|
||||
//now we need to format the items in the dictionary because we always want to have an array
|
||||
var configItems = [];
|
||||
var vals = _.values($scope.model.config.items);
|
||||
var keys = _.keys($scope.model.config.items);
|
||||
for (var i = 0; i < vals.length; i++) {
|
||||
configItems.push({ id: keys[i], sortOrder: vals[i].sortOrder, value: vals[i].value });
|
||||
//we can't really do anything if the config isn't an object
|
||||
if (angular.isObject($scope.model.config.items)) {
|
||||
|
||||
//now we need to format the items in the dictionary because we always want to have an array
|
||||
var configItems = [];
|
||||
var vals = _.values($scope.model.config.items);
|
||||
var keys = _.keys($scope.model.config.items);
|
||||
for (var i = 0; i < vals.length; i++) {
|
||||
configItems.push({ id: keys[i], sortOrder: vals[i].sortOrder, value: vals[i].value });
|
||||
}
|
||||
|
||||
//ensure the items are sorted by the provided sort order
|
||||
configItems.sort(function (a, b) { return (a.sortOrder > b.sortOrder) ? 1 : ((b.sortOrder > a.sortOrder) ? -1 : 0); });
|
||||
|
||||
if ($scope.model.value === null || $scope.model.value === undefined) {
|
||||
$scope.model.value = [];
|
||||
}
|
||||
|
||||
updateViewModel(configItems);
|
||||
|
||||
//watch the model.value in case it changes so that we can keep our view model in sync
|
||||
$scope.$watchCollection("model.value",
|
||||
function (newVal) {
|
||||
updateViewModel(configItems);
|
||||
});
|
||||
}
|
||||
|
||||
//ensure the items are sorted by the provided sort order
|
||||
configItems.sort(function (a, b) { return (a.sortOrder > b.sortOrder) ? 1 : ((b.sortOrder > a.sortOrder) ? -1 : 0); });
|
||||
|
||||
if ($scope.model.value === null || $scope.model.value === undefined) {
|
||||
$scope.model.value = [];
|
||||
}
|
||||
|
||||
updateViewModel(configItems);
|
||||
|
||||
//watch the model.value in case it changes so that we can keep our view model in sync
|
||||
$scope.$watchCollection("model.value",
|
||||
function(newVal) {
|
||||
updateViewModel(configItems);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function updateViewModel(configItems) {
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
angular.module("umbraco").controller("Umbraco.PropertyEditors.RadioButtonsController",
|
||||
function($scope) {
|
||||
|
||||
if (angular.isObject($scope.model.config.items)) {
|
||||
|
||||
//now we need to format the items in the dictionary because we always want to have an array
|
||||
var newItems = [];
|
||||
var vals = _.values($scope.model.config.items);
|
||||
var keys = _.keys($scope.model.config.items);
|
||||
for (var i = 0; i < vals.length; i++) {
|
||||
newItems.push({ id: keys[i], sortOrder: vals[i].sortOrder, value: vals[i].value });
|
||||
|
||||
function init() {
|
||||
|
||||
//we can't really do anything if the config isn't an object
|
||||
if (angular.isObject($scope.model.config.items)) {
|
||||
|
||||
//now we need to format the items in the dictionary because we always want to have an array
|
||||
var configItems = [];
|
||||
var vals = _.values($scope.model.config.items);
|
||||
var keys = _.keys($scope.model.config.items);
|
||||
for (var i = 0; i < vals.length; i++) {
|
||||
configItems.push({ id: keys[i], sortOrder: vals[i].sortOrder, value: vals[i].value });
|
||||
}
|
||||
|
||||
//ensure the items are sorted by the provided sort order
|
||||
configItems.sort(function (a, b) { return (a.sortOrder > b.sortOrder) ? 1 : ((b.sortOrder > a.sortOrder) ? -1 : 0); });
|
||||
|
||||
$scope.configItems = configItems;
|
||||
}
|
||||
|
||||
//ensure the items are sorted by the provided sort order
|
||||
newItems.sort(function (a, b) { return (a.sortOrder > b.sortOrder) ? 1 : ((b.sortOrder > a.sortOrder) ? -1 : 0); });
|
||||
|
||||
//re-assign
|
||||
$scope.model.config.items = newItems;
|
||||
$scope.htmlId = "radiobuttons-" + $scope.model.alias + String.CreateGuid();
|
||||
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<div class="umb-property-editor umb-radiobuttons" ng-controller="Umbraco.PropertyEditors.RadioButtonsController">
|
||||
<ul class="unstyled">
|
||||
<li ng-repeat="item in model.config.items">
|
||||
<li ng-repeat="item in configItems track by item.id">
|
||||
<label class="radio">
|
||||
<input type="radio" name="radiobuttons-{{model.alias}}"
|
||||
<input type="radio" name="{{htmlId}}"
|
||||
value="{{item.id}}"
|
||||
ng-model="model.value" />
|
||||
{{item.value}}
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user