Copied to clipboard

Flag this post as spam?

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


  • Jonathan Roberts 336 posts 938 karma points
    Jan 26, 2015 @ 13:25
    Jonathan Roberts
    1

    Contour custom TinyMCE FieldType

    Hi,

     

    We are using Umbraco 7.2 with Contour and we want to create our own TinyMCE FieldType so we can post HTML but we are getting into some difficulties. When following the code similar to the link found here : http://our.umbraco.org/forum/umbraco-pro/contour/38385-Custom-Field-Type-in-V3 but we are getting no suitable method found to override. We are inheriting the FieldType as described in the post.

     

    Are there any uptodate examples on how to create a TinyMCE FieldType for Contour?

     

    Many thanks

     

    Jon

  • Jonathan Roberts 336 posts 938 karma points
    Jan 27, 2015 @ 09:22
    Jonathan Roberts
    0

    Hi,

    Can I ask if this is at all possible?

    Jon

  • Dennis Aaen 4431 posts 17884 karma points admin hq c-trib
    Jan 27, 2015 @ 09:29
    Dennis Aaen
    0

    Hi Jonanthan,

    Please don't double post - It creates too much noice and can lead to unwanted confusion :) http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/60783-Create-TinyMCE-Editor-for-Contour-

    That being said, I assume that you are using Umbraco Forms, since you are using Umbraco 7.2. Try to see the documentation about how to extending the Umbraco Forms http://our.umbraco.org/documentation/Products/UmbracoForms/Developer/Extending/ and specific about field types: http://our.umbraco.org/documentation/Products/UmbracoForms/Developer/Extending/Adding-a-Fieldtype

    Hope this helps,

    /Dennis

     

  • Jonathan Roberts 336 posts 938 karma points
    Jan 27, 2015 @ 09:37
    Jonathan Roberts
    0

    Hi,

    Thanks for your reply and apologies for the Double Entry - its a bit confusing to where to place these questions.

    Regarding the post above, I have seen these types of posts before but cannot find one for the Tiny MCE. Do you know if there is anything available and why I am getting a no suitable method found to override?

     

    Thanks

    Jon

  • Dennis Aaen 4431 posts 17884 karma points admin hq c-trib
    Jan 27, 2015 @ 09:47
    Dennis Aaen
    0

    Hi Jon,

    Can see Anthony are getting the same no suitable method found to override message like you in this thread http://our.umbraco.org/forum/umbraco-pro/contour/27135-country-picker-in-Contour. To it looks like the example is for Umbraco Forms. But I am not a backend developer :-)

    Perhaps you can solve it by reading through the thread above.

    Hope this helps,

    /Dennis

  • Jonathan Roberts 336 posts 938 karma points
    Jan 27, 2015 @ 09:52
    Jonathan Roberts
    0

    Hi,

    Thanks for your reply.

    I will wait for a back end developer to answer my question then as I have already read this article.

     

    Thanks

    Jon

  • Jonathan Roberts 336 posts 938 karma points
    Jan 27, 2015 @ 15:01
    Jonathan Roberts
    0

    This is the code that I am using

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using Umbraco.Forms.Core;

    using Umbraco.Forms.UI;

    using Umbraco.Forms.Core.Controls;

    using System.Web.UI.WebControls;

    using System.Web.UI; using umb = umbraco; using umbraco.editorControls;

    namespace CustomContour

    {

    public class RichTextEditor_ContourFieldType : Umbraco.Forms.Core.FieldType

    {
    

    [Umbraco.Forms.Core.Attributes.Setting("RichTextArea", description = "RichTextArea")] public string richTextArea { get; set; }

        private TextBox txt = new TextBox();
    
        public List<object> _value;
    
    
    
        public RichTextEditor_ContourFieldType()
        {
            //Provider
            this.Id = new Guid("02CEC34E-502F-4ED7-9000-BA1A7FDFABD3");
            this.Name = "RichTextArea";
            this.Description = "Renders Content";
    
            this.Icon = "textfield.png";
            this.DataType = FieldDataType.String;
    
        }
    
        public override WebControl Editor
        {
            get
            {
                if (_value.Count > 0)
                    txt.Text = _value[0].ToString();
    
    
    
                return txt;
            }
            set { Editor = value; }
        }
    
        public override List<Object> Values
        {
            get
            {
                if (txt.Text != "")
                {
                    _value.Clear();
                    _value.Add(txt.Text);
                }
                return _value;
            }
            set { _value = value; }
        }
    
        public override string RenderPreview()
        {
            string o = string.Empty;
            o = @"<div class=""richTextArea"">" + richTextArea + "</div>";
            return o;
        }
    
        public override string RenderPreviewWithPrevalues(List<object> prevalues)
        {
            return RenderPreview();
        }
    }
    

    }

  • Paul de Quant 340 posts 1329 karma points
    Jan 27, 2015 @ 16:40
    Paul de Quant
    100

    Hi Jon,

    I've had a little look at this and I believe the reason why it's working for you is that your using an older version of Contour - I presume you're on the latest version (4 I think).

    Anyway I've managed to successfully create a Rich Text Editor for Contour.

    Firstly drop the overrides. They don't exist

    I've kept it basic for now:

    namespace CustomContour
    

    { public class RichTextEditor : Umbraco.Forms.Core.FieldType { [Umbraco.Forms.Core.Attributes.Setting("Rich Text Editor", description = "Rich Text Editor to allow users to submit formatted HTML")] public string richTextArea { get; set; } private TextBox txt = new TextBox(); public List

  • Jonathan Roberts 336 posts 938 karma points
    Jan 27, 2015 @ 16:44
    Jonathan Roberts
    0

    Amazing - many thanks for all your hard work - you are a life saver Thanks again, Jon

  • shailesh 2 posts 22 karma points
    Dec 28, 2017 @ 09:28
    shailesh
    0

    Thanks for the nice post ,

    I tried the same things at my end and I am able to save data inside one table e.g employee but when i retrieve data then it's not able to get and set inside tinymce so can any one tell me what could not the problem

    here is my form.cshtml @using Umbraco.Forms.Core @using Umbraco.Forms.Mvc.Models @using Umbraco.Forms.Mvc.BusinessLogic @using Umbraco.Forms.MVC.Extensions @using Umbraco.Web @using ClientDependency.Core.Mvc;

    @model Umbraco.Forms.Mvc.Models.FormViewModel @{ Html.EnableClientValidation(true); Html.EnableUnobtrusiveJavaScript(true); }

    @if (Model.SubmitHandled) { if (Model.RenderMode == "full" || Model.RenderMode == "form") {

    @Html.Raw(Model.MessageOnSubmit)

    } } else { if (Model.RenderMode == "full" || Model.RenderMode == "form") {

         <div id="contour_form_@Model.FormClientId" class="contour @Model.CssClass">
    
             @using (Html.BeginUmbracoForm<Umbraco.Forms.Web.Controllers.UmbracoFormsController>("HandleForm"))
             {
                 @Html.AntiForgeryToken()
    
                 <input type="hidden" name="FormId" value="@Model.FormId" />
                 @Html.HiddenFor(x => Model.FormName)
                 @Html.HiddenFor(x => Model.RecordId)
                 @Html.HiddenFor(x => Model.PreviousClicked)
    
                 <input type="hidden" name="FormStep" value="@Model.FormStep" />
                 <input type="hidden" name="RecordState" value="@Model.RecordState"/>
    
                 <div class="contourPage">
    
                     @if (string.IsNullOrEmpty(Model.CurrentPage.Caption) == false)
                     {
                         <h4 class="contourPageName">@Html.Raw(Model.CurrentPage.Caption)</h4>                    
                     }
    
                     @if (Model.ShowValidationSummary)
                     {
                         @Html.ValidationSummary(false)
                     }
    
                     @foreach (FieldsetViewModel fs in Model.CurrentPage.Fieldsets)
                     {
                        <fieldset class="contourFieldSet" id="@fs.Id">
                            @if (string.IsNullOrEmpty(fs.Caption) == false)
                            {
                                <legend>@Html.Raw(fs.Caption)</legend>
                            }
    
                            <div class="row-fluid">
                                @foreach (var c in fs.Containers)
                                {
    
                                    <div class="@("span" + c.Width) @("col-md-" + c.Width)">
                                        @foreach (FieldViewModel f in c.Fields)
                                        {
                                            bool hidden = f.HasCondition && f.ConditionActionType == FieldConditionActionType.Show;
    
                                            <div class="@f.CssClass" @{ if (hidden) { <text> style="display: none" </text>  } }>
    
                                                @if (!f.HideLabel)
                                                {
                                                    <label for="@f.Id" class="fieldLabel">
                                                        @Html.Raw(f.Caption) @if (f.ShowIndicator)
                                                        {
                                                            <span class="contourIndicator">@Model.Indicator</span>
                                                        }
                                                    </label>
                                                }
                                                @if (!string.IsNullOrEmpty(f.ToolTip))
                                                {
                                                    <span class="help-block">@f.ToolTip</span>
                                                }
    
                                                <div>
                                                   @* <b>@Model.FormId.ToString()</b><br />
                                                    <b>@f.FieldType.FieldTypeViewName</b><br />
                                                    <b>@f.Caption</b><br />
                                                    <b>@f.Id</b>*@
                                                    @Html.Partial(FieldViewResolver.GetFieldView(Model.FormId.ToString(), f.FieldType.FieldTypeViewName, f.Caption), f)
                                                    @if (Model.ShowFieldValidaton)
                                                    {
                                                        @Html.ValidationMessage(f.Id)
                                                    }
                                                </div>
                                            </div>
    
                                        }
    
                                    </div>
    
                                }
                            </div>
    
                        </fieldset>
                     }
    
                     <div style="display: none">
                         <input type="text" name="@Model.FormId.ToString().Replace("-", "")" />
                     </div>
    
    
                     <div class="contourNavigation row-fluid">
                         <div class="col-md-12">
                             @if (Model.IsMultiPage)
                             {
                                 if (!Model.IsFirstPage)
                                 {
                                     <input class="btn prev cancel" type="submit" value="@Model.PreviousCaption" name="__prev"/>
                                 }
                                 if (!Model.IsLastPage)
                                 {
                                     <input type="submit" class="btn next" value="@Model.NextCaption" name="next"/>
                                 }
                                 if (Model.IsLastPage)
                                 {
                                     <input type="submit" class="btn primary" value="@Model.SubmitCaption" name="submitbtn"/>
                                 }
                             }
                             else
                             {
                                 <input type="submit" class="btn primary" value="@Model.SubmitCaption" name="submitbtn"/>
                             }
                         </div>
                     </div>
    
                 </div>
             }
         </div>
    
    }
    
    if (Model.CurrentPage.PartialViewFiles.Any())
    {
        foreach (var partial in Model.CurrentPage.PartialViewFiles)
        {
            @Html.Partial(partial.Value)
        }
    }
    
    if (Model.RenderMode == "full" || Model.RenderMode == "script")
    {
        @Html.Partial(FormViewResolver.GetScriptView(Model.FormId), Model)
    
        foreach (var script in Model.CurrentPage.JavascriptFiles)
        {
            if (Model.UseClientDependency)
            {
                Html.RequiresJs(script.Value);
            }
            else
            {
    
    
    <script type="text/javascript" src="@Url.Content(script.Value)"></script>
    
    
            }
        }
    
        if (Model.CurrentPage.JavascriptCommands.Count > 0)
        {
    
    
    
    <script type="text/javascript">
                @foreach (var cmd in Model.CurrentPage.JavascriptCommands)
                {
                    <text>@Html.Raw(cmd)</text>
                }
    
            </script>
    
    
        }
    
        foreach (var css in Model.CurrentPage.CssFiles)
        {
            if (Model.UseClientDependency)
            {
                Html.RequiresCss(css.Value);
            }
            else
            {
                <link rel="stylesheet" href="@Url.Content(css.Value)" />
            }
        }
    
    }
    

    }

    And Inside Views\Partials\Forms\Fieldtypes\FieldType.RichTextEditor.cshtml file below is a code

    @model Umbraco.Forms.Mvc.Models.FieldViewModel

    <script type="text/javascript" src="@Url.Content("~/umbraco/lib/tinymce/tinymce.min.js")"></script>
    
    
    
    
    
    <script type="text/javascript">
    
    tinymce.init({
        selector: "textarea.rte",
        plugins: [
            "autolink autosave link image lists charmap preview hr anchor pagebreak spellchecker",
            "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
            "table contextmenu directionality emoticons template textcolor paste textcolor"
        ],
        toolbar1: "bold italic | link unlink | formatselect",
        //toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | inserttime preview | forecolor backcolor",
        //toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",
        remove_linebreaks: false,
        relative_urls: false,
        menubar: false,
        toolbar_items_size: 'small'
    });
    

Please Sign in or register to post replies

Write your reply to:

Draft