Copied to clipboard

Flag this post as spam?

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


  • Anders Schmidt 76 posts 207 karma points
    May 18, 2014 @ 15:15
    Anders Schmidt
    0

    Updating textarear val inside a property editor with jQuery

    I am creating a Property Editor With my own Html Editor in jQuery and a textarear for HTML Content.

    Text Arear looks like this and working fine when tying as normal and saving:

    <textarea id="htmlPlaceholder" ng-model="model.value" class="wmd-input" id="wmd-input-{{model.alias}}"></textarea>

    I am simply using jquery for updating textArear Like This:

    $('#htmlPlaceholder').val(newHtml);

    But when saving Umbraco's now grapping new insertet content.

    Thanks n advance :-)

     

     

     

     

     

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    May 19, 2014 @ 10:33
    Alex Skrypnyk
    0

    Hi Anders,

    Where did you place your js code ? What event ?

    Thanks, Alex

  • Anders Schmidt 76 posts 207 karma points
    May 19, 2014 @ 10:52
    Anders Schmidt
    0

    Hi Alex, Thanks for anwsering.

    My code is in: facebookTabEditor.controller.js

    code:

    angular.module("umbraco").controller("facebookTabEditor", function ($scope, assetsService) {
    
        assetsService.loadCss("http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css");
        assetsService.loadCss("/App_Plugins/stylesGeneral/dragDropStyles.css");
        assetsService.loadCss("/App_Plugins/stylesGeneral/jquery.notebook.min.css");
    
    
        assetsService.load(["/App_Plugins/jsGeneral/jquery.notebook.js"]).then(function () {
    
            $('#container').bind("DOMSubtreeModified", function () {
    
                var newHtml = $('#container').html();            
                $('#htmlPlaceholder').val(newHtml);
    
            });
    
            //SYNC AF CONTAINER OG TEXTAREAR VED PAGELOAD
            var startHtml = $("#htmlPlaceholder").val();
            $('#container').html(startHtml);
    
        });
    
    });
  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 19, 2014 @ 11:02
    Sebastiaan Janssen
    100

    Looks like the jquery.notebook plugin replaces the textarea with something else, subscribe to the on change event to update the value in the scope (which is what Umbraco will store when you save the node):

    $('.my-editor').on('contentChange', function(e) {
        $scope.model.value = editor.getSession().getValue();
    });
    
  • Anders Schmidt 76 posts 207 karma points
    May 19, 2014 @ 11:15
    Anders Schmidt
    0

    Hi Sebastiaan,

    Thanks. This also helped me:

            $('#container').bind("DOMSubtreeModified", function () {
                var newHtml = $('#container').html();
                $scope.model.value = newHtml;
            });

     

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 19, 2014 @ 11:25
    Sebastiaan Janssen
    0

    The problem with this is that you can now not have more than one editor on each document type (as you're hardcoding the Id).

    I would suggest updating to something like this view (note the change from id to class):

    <textarea class="notebook-editor-item" ng-model="model.value" class="wmd-input" id="wmd-input-{{model.alias}}"></textarea>

    And this controller:

    assetsService.load(["/App_Plugins/jsGeneral/jquery.notebook.js"]).then(function () {
    
    angular.forEach($element.find('.notebook-editor-item'), function (element) {
    
       $(element).notebook();
    
       $(element).on('contentChange', function(e) {
           $scope.model.value = e.originalEvent.detail.content;
       });
    
     }
    });
    

    This way you can have multiples of them and you're not doing too much jQuery. The thing about Angular is that people need to unlearn their bad jQuery habits a little bit as this way is much better and doesn't rely on the DOM so much.

Please Sign in or register to post replies

Write your reply to:

Draft