Drop down list seems to be working with pre-values :)

This commit is contained in:
Shannon
2013-08-23 18:38:33 +10:00
parent fbaaf7a6cb
commit b1f3e8d8ef
4 changed files with 12 additions and 9 deletions

View File

@@ -8,12 +8,14 @@ angular.module("umbraco").controller("Umbraco.Editors.DropdownController",
keyName: "alias",
valueName: "name"
};
//map the user config
angular.extend(config, $scope.model.config);
//map back to the model
$scope.model.config = config;
$scope.selectExpression = "e." + config.keyName + " as e." + config.valueName + " for e in model.config.items";
//now we need to format the items in the array because we always want to have a dictionary
for (var i = 0; i < $scope.model.config.items.length; i++) {
if (angular.isString($scope.model.config.items[i])) {

View File

@@ -1,7 +1,6 @@
<div ng-controller="Umbraco.Editors.DropdownController">
<select name="dropDownList"
ng-model="model.value"
required
ng-options="e.alias as e.name for e in model.config.items"></select>
ng-options="{{selectExpression}}"></select>
</div>

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Web.PropertyEditors
{
/// <summary>
/// The editor is expecting a json array for a field with a key named "temp" so we need to format the persisted values
/// The editor is expecting a json array for a field with a key named "items" so we need to format the persisted values
/// to this format to be used in the editor.
/// </summary>
/// <param name="defaultPreVals"></param>
@@ -24,9 +24,8 @@ namespace Umbraco.Web.PropertyEditors
{
var dictionary = PreValueCollection.AsDictionary(persistedPreVals);
var arrayOfVals = dictionary.Select(item => item.Value).ToList();
//var json = JsonConvert.SerializeObject(arrayOfVals);
return new Dictionary<string, object> { { "temp", arrayOfVals } };
return new Dictionary<string, object> { { "items", arrayOfVals } };
}
/// <summary>
@@ -42,7 +41,7 @@ namespace Umbraco.Web.PropertyEditors
/// </remarks>
public override IDictionary<string, string> FormatDataForPersistence(IDictionary<string, object> editorValue, PreValueCollection currentValue)
{
var val = editorValue["temp"] as JArray;
var val = editorValue["items"] as JArray;
var result = new Dictionary<string, string>();
if (val == null)

View File

@@ -17,10 +17,13 @@ namespace Umbraco.Web.PropertyEditors
new PreValueField
{
Description = "Add and remove values for the drop down list",
//we're going to call this 'temp' because we are going to override the
//we're going to call this 'items' because we are going to override the
//serialization of the pre-values to ensure that each one gets saved with it's own key
//(new db row per pre-value, thus to maintain backwards compatibility)
Key = "temp",
//It's also important to note that by default the dropdown angular controller is expecting the
// config options to come in with a property called 'items'
Key = "items",
Name = ui.Text("editdatatype", "addPrevalue"),
View = "Views/PropertyEditors/dropdown/dropdown.prevalue.html"
}