Copied to clipboard

Flag this post as spam?

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


  • ariel.jugesh 9 posts 80 karma points
    Apr 19, 2017 @ 10:55
    ariel.jugesh
    1

    Umbraco 7 custom RTE with angularjs

    I am following this example (Option 2) - http://www.enkelmedia.se/blogg/2013/12/4/umbraco-7-use-the-rich-text-editor-tinymce-in-a-custom-section.aspx

    I want to update value of rich text editor on change of dropdown but unable to do so.

    I am updating value like this : $scope.myProperty.value = "Test";

    This is updating the value of myProperty model but not updating text of rich text editor.

  • Jonathan Richards 288 posts 1742 karma points MVP
    Apr 19, 2017 @ 14:17
    Jonathan Richards
    0

    Hi Ariel,

    THE PROPER WAY TO DO IT

    First part is to add some functionality to your instance of tinymce so that it can set values.

    Do you see the bit

    $scope.property = {
                label: 'bodyText',
                description: 'Load some stuff here',
                view: 'rte',
                config: {
                    editor: {
                        toolbar: ["code", "undo", "redo", "cut", "styleselect", "bold", "italic", "alignleft", "aligncenter", "alignright", "bullist", "numlist", "link", "umbmediapicker", "umbmacro", "table", "umbembeddialog"],
                        stylesheets: [],
                        dimensions: { height: 400, width: 250 }
                    }
                }
            };
    

    You need to add a field and your own function, in this example, I've called it id and setContent()

      $scope.property = {
            id: 'Make a unique ID here',
            setContent: function (content) {
                for (var i = 0; i != tinymce.editors.length; i++) {
                    if (tinymce.editors[i].id == $scope.property.id) {
                        tinymce.editors[i].setContent(content);
                    }
                }
            },
            label: 'bodyText',
            description: 'Load some stuff here',
            view: 'rte',
            config: {
                editor: {
                    toolbar: ["code", "undo", "redo", "cut", "styleselect", "bold", "italic", "alignleft", "aligncenter", "alignright", "bullist", "numlist", "link", "umbmediapicker", "umbmacro", "table", "umbembeddialog"],
                    stylesheets: [],
                    dimensions: { height: 400, width: 250 }
                }
            }
        };
    

    Then you will need to pass a reference to this rte instance to the code that sets the dropdown list. Its a little hard for me to say exactly how you would do this, you might want to consider an angular service to pass the value across.

    HACKY WAY - I DON'T VOUCH THIS WILL WORK AT ALL

    Add an Id field to $scope.property like

      $scope.property = {
            id: 'Make a unique ID here',
            label: 'bodyText',
    

    but in your case,. try and give Id a better constant value

    Then in the code that sets the dropdown list call

    tinymce.get('Make a unique ID here').setContent('This is the content I want');
    

    For further info about tinyMce's setContent()

    I hope this helps

    Cheers

    Jonathan

  • ariel.jugesh 9 posts 80 karma points
    Apr 20, 2017 @ 05:02
    ariel.jugesh
    0

    Hi Jonathan,

    Thank you for giving your precious time.

    Used your code but i am getting an error on console "Tiny mice is not defined" for this tinymce.get('myId').setContent('This is the content I want').

    I think this "tinymce.get().." is used if we are using Jquery tinymce but i am using of angularjs.

    Below is my code :


           //.js
           $scope.txtWashing = {
           label: 'bodyText',
           description: 'Load some stuff here',
           view: 'rte',
           config: {
               editor: {
                   toolbar: ["code", "undo", "redo", "cut", "styleselect", "bold", "italic", "alignleft", "aligncenter", "alignright", "bullist", "numlist", "link", "umbmediapicker", "umbmacro", "table", "umbembeddialog"],
                   stylesheets: [],
                   dimensions: { height: 300, width: 600 }
               }
           },
           value: "Test"
       };
    
    
    
      //html
     <umb-editor model="txtWashing"></umb-editor>
    
    --------------------------------------------------------------------
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 20, 2017 @ 07:03
    Dave Woestenborghs
    0

    Hi Ariel,

    I have tried a different way of displaying the RTE. Read the part of reusing existing datatypes in this article : http://24days.in/umbraco-cms/2014/umbraco-angular-tips/

    That worked very well for me

    Dave

  • ariel.jugesh 9 posts 80 karma points
    Apr 20, 2017 @ 11:38
    ariel.jugesh
    0

    Hi Dave, I followed your example too. It displays content perfectly but how to change RTE inside text.

    For example , there is a button below the RTE and if we want to change text of RTE on click of button , then how would we do it ? (This is my requirement)

    I used the following code to update but it did not change text of RTE:

     $scope.btnUpdate = function ( ) { 
     $scope.model.rtevalue = "A new text";
      }
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 20, 2017 @ 11:50
    Dave Woestenborghs
    0

    Hi Ariel,

    From my code example you should do this :

    $scope.rteField[0].value = 'your value'
    

    Dave

  • ariel.jugesh 9 posts 80 karma points
    Apr 20, 2017 @ 12:34
    ariel.jugesh
    0

    Hi Dave,

    I wrote this on button's click ,

       $scope.rteField[0].value = 'your value'
    

    But this only updated the value of $scope.rteField[0].value , not text of RTE (That is still same as it was before click).

  • ariel.jugesh 9 posts 80 karma points
    Apr 25, 2017 @ 12:48
    ariel.jugesh
    0

    ???

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 25, 2017 @ 12:57
    Dave Woestenborghs
    0

    Can you post your full code ?

Please Sign in or register to post replies

Write your reply to:

Draft