Copied to clipboard

Flag this post as spam?

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


  • Jorge Ribeiro 29 posts 213 karma points
    Feb 11, 2021 @ 17:49
    Jorge Ribeiro
    0

    RTE in custom section HOW TO

    Hi

    I've made a custom section in backoffice in order to allow admins to create articles for a newsletter. This newsletter wont be directly on site so I do not want to create doc types. Instead, I use the backoffice to create those articles in a custom DB. Each article has a title and a content which I was trying to get from umbraco's TinyMCE RTE. I was able to get it to work partially... there is not much of documentation arround so I've been strugling a bit.

    Apperently the RTE works and I can get the content entered from it but a strange thing happens... my backoffice buttons (save, and others) stop working after I navigate to that custom section where the RTE is loaded. If I start umbraco and dont enter my custom section, all works as expected... but the moment I enter the page where my RTE is, in my custom section, from then on Save buttons stop responding all over my backoffice. I guess that's some kind of a mess with angular.js I'm doing here. It seems to has something related to the ng-form where my RTE is... some kind of validation or so, or some event been hanging loose somewhere.

    I'm pretty newbie with angular.js and umbraco backoffice. I do not know in depth how this things really work. I really need help here... the posts I've been reading do not provide much info.

    Here's my html

    <div class="umb-dashboard" ng-controller="newsletterArticleManagementController as mng">
        ...
        <div>
            <input type="text" ng-model="title"/>
        </div>
        <div>
            <ng-form val-form-manager>
                <umb-property property="property" ng-repeat="property in rteArtigo">
                    <umb-editor model="property"></umb-editor>
                </umb-property>
            </ng-form>
        </div>
        ...
        <button ng-click="mng.save()" class="btn publish">Save</button>
        ...
    </div>
    

    Here's my js controller

    // RTE.
    $scope.rteArtigo = [{
        view: "/App_Plugins/NewsletterSection/backoffice/newsletterManagement/rte.html",
        config: {
            editor: {           
                toolbar: ["ace", "undo", "redo", "bold", "italic", "alignleft", "aligncenter", "alignright", "bullist", "numlist", "link", "umbmediapicker", "fullscreen"],
                style_formats: [{ title: "Heading 1", inline: "h1" }],
                plugins: ["fullscreen"],
                stylesheets: [],
                dimensions: { height: 300 }
            }
        },
        value: ""
    }];
    ...
    vm.save = function (form) {
        // entered data.
        var title = $scope.title;
        var data = $scope.rteArtigo[0].value;
        // here I use an ajax call to save data.
    }
    

    I do not use anything besides ng-click events where all is processed. Data from $scope.rteArtigo[0].value is fetched and saved in a DB. If I take ng-form tag and include other inputs, like the title above, when my page lose focus Umbraco prompts the usual "do you want do discard changes" message... but if ng-form only has RTE editor inside it doesnt prompt. I wonder if that is not one of the reasons my save buttons stopped working in other backoffice sections...

    I really need help here!

    Regards,

    Jorge

  • Jorge Ribeiro 29 posts 213 karma points
    Feb 12, 2021 @ 11:38
    Jorge Ribeiro
    103

    To anyone with needs to add RTE to custom section here is what I discovered:

    In html use this:

    <ng-form >
        <umb-property-editor model="rteArtigo"></umb-property-editor>
    </ng-form>
    

    in js controller use this:

    $scope.rteArtigo = {
        view: "rte",
        config: {
            editor: {
                toolbar: ["ace", "undo", "redo", "bold", "italic", "alignleft", "aligncenter", "alignright", "bullist", "numlist", "link", "umbmediapicker", "fullscreen"],
                style_formats: [{ title: "Heading 1", inline: "h1" }],
                plugins: ["fullscreen"],
                stylesheets: [],
                dimensions: { height: 300 }
            }
        }
    };
    

    That works!

    JR

Please Sign in or register to post replies

Write your reply to:

Draft