Copied to clipboard

Flag this post as spam?

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


  • Mihail 39 posts 142 karma points
    Jun 07, 2017 @ 07:06
    Mihail
    0

    Data is not saved if use custom property editor in Umbraco

    I create custom property editor which takes all available languages in Umbraco like:

    angular.module("umbraco").controller("MyLanguageController", function ($scope, myLanguageService) {
       $scope.items = [];
    
       myLanguageService.getAll().then( function( result ) {
          if( result && result.data && result.data.length ) {
             $scope.items = result.data;
          }
       } );
    });
    

    and

    angular.module("umbraco.resources")
       .factory("myLanguageService", function ($http) {
    
          return {
             getAll: function () {
                return $http.get("/umbraco/backoffice/MyControllerSide/GetAll", { "dataType": "json" });
             }
          };
    });
    

    The view:

    <div ng-controller="MyLanguageController" id="language">
       <ul>
          <li ng-repeat="item in items" class="checkbox">
             <label>
                <input type="checkbox" value="{{item.IsoCode}}"> {{item.CultureName}}
             </label>
          </li>
       </ul>
    </div>
    

    The package manifest contains:

    {
        propertyEditors: [
            {
                alias: "MyLanguageAlias",
                name: "Language Selector",
                icon: "icon-umb-translation",
                hideLabel: true,
                valueType: "JSON",
                editor: {
                    view: "~/App_Plugins/MyLanguageSelector/backoffice/view.html"
                }
            }
        ],
      ...
    

    and C# code:

      [HttpGet]
      public JsonResult GetAll()
      {
         IEnumerable<ILanguage> languages = ApplicationContext.Services.LocalizationService.GetAllLanguages() ?? new List<ILanguage>(0);
         IEnumerable<TranslationLanguageModel> model =
            languages.Select(s => new MyLanguageModel { CultureName = s.CultureInfo.DisplayName, IsoCode = s.IsoCode });
    
         return Json(model, JsonRequestBehavior.AllowGet);
      }
    

    I created new data type in Umbraco/Developer section, and I add it in document type:

    enter image description here

    When I save document, the value for that property is null. I don't understand why.

    And when come back to content, then nothing is checked.

    What should I do ?

  • Delete 61 posts 450 karma points
    Jun 07, 2017 @ 07:59
    Delete
    1

    Hi,

    Because you don't store the value you need.

    <input type="checkbox" value="{{item.IsoCode}}"> {{item.CultureName}}
    

    There is not enough parts of the code like this. But, this code you need check.

     <input type="checkbox" ng-model="model.value" value="{{item.IsoCode}}"> {{item.CultureName}}
    

    Another example

    You may need to add a new method that will call when you select some options and will save the correct value in the model.value in angular controller.

    Regards,

    Vitaly

Please Sign in or register to post replies

Write your reply to:

Draft