Jump to:

794 Posts in 408 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » HTMLTextField in Widget

Discuss SilverStripe Widgets.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 4433 Views
  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    HTMLTextField in Widget Link to this post

    I've got a very simple widget, where I want the user to edit HTMLText field. I've tried
    HTMLEditorField, SimpleTinyMCEField and SimpleWysiwygField from the DOM.

    The HTMLEditorField shows the editor, but the content is neither loaded nor saved. SimpleTinyMCEField and SimpleWysiwygField show the content but not any tiny mce editor fields.

    Any pointers to get this working?

    <?php

    class HTMLTextWidget extends Widget {
       static $db = array(
          'Title' => 'Text',
          'WidgetContent' => 'HTMLText',
       );

       static $title = "Content";
       static $cmsTitle = "Content Widget";
       static $description = "Add a content block to the sidebar";

       function Title() {
          return $this->Title;
       }

       function getCMSFields() {
          return new FieldSet(
             new TextField("Title", "Title"),
             //new HTMLEditorField("WidgetContent", "Content")
             new SimpleTinyMCEField("WidgetContent", "Content")
             //new SimpleWysiwygField("WidgetContent", "Content")
             //new TextareaField("WidgetContent", "Content")
          );
       }
    }

    ?>

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: HTMLTextField in Widget Link to this post

    Hi Marijn,

    I just looked at this and I'd say it was something in tinyMCE that is not "getting" the contents of the text box. I say that because the text in the database (if you were to edit it manually) appears in the the textarea "behind" the tinyMCE and then gets submitted for saving and can be seen by logging $_REQUEST['Widget'] in \cms\code\WidgetAreaEditor.php function saveInto(DataObject $record).

    So I think it is something todo with the way widget areas use indexes type stuff to hold multiple items e.g. 'Widget[SideBar][30][WidgetContent]' is what the name of the field in my browser - instead of 'Form_EditForm_Content' for teh main page content.

    So, as I said, I figure it is something in the communication between tinyMCE and the textarea due to the id. I had issues when I tried to do jQuery finding a widget item by id in the past and ended up doing something else much more simple without the jQuery due to these issues.

    Hope this helps,

    Barry

    p.s. I was testing with 'new HTMLEditorField("WidgetContent", "WidgetContent")'

  • x75
    Avatar
    Community Member
    42 Posts

    Re: HTMLTextField in Widget Link to this post

    Hi,

    this is probably the same problem that the HtmlContentWidget has:
    http://www.silverstripe.org/widgets-2/show/255189?start=16#post278417

    As far as I know the HtmlContentWidget is not updated anymore. Since it is a common request, I was thinking about creating a new Modul but never found the time. Would you be willing to release your widget for others to use?

    Thanks
    Johannes

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: HTMLTextField in Widget Link to this post

    I ended up just using a plain text field, as the particular user this was for is quite tech savvy. If I ever develop a HTML Widget I'll make sure to release it.

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: HTMLTextField in Widget Link to this post

    hello @MarijnKampf,

    I have come across this problem before. What I did is to use some goodies which ships with the DataObjectManager Module. There are some fields called SimpleTinyMCEField, SimpleHTMLEditorField, etc.

    take a look at them, they cant do much, at least they can help you.

    cheers!

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: HTMLTextField in Widget Link to this post

    Hi Nivanka,

    It's been a while, but I've come across another scenario where it would be nice to have an HTML widget, I had a brief look into SimpleTinyMCEField and SimpleHTMLEditorField, but couldn't get them to work out of the box. (The fields aren't shown in my widget). Do you have some sample code of using them in a widget?

    Cheers,

    Marijn.

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: HTMLTextField in Widget Link to this post

    I remember seeing something by Martijn on the google dev list about a patch to allow this - as I said before it all comes down to the ids being stuff like "Widget[SideBar][42][LinkToSiteTreeID]" - here is is http://groups.google.com/group/silverstripe-dev/msg/1a3b1292c4f46117

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: HTMLTextField in Widget Link to this post

    We got our widgets working on all pages eventually, here's our solution. Hopefully it helps!

    http://www.clickheredigital.co.uk/blog/bad-widget-class-name-given-our-experience-with-widgets-on-any-silverstripe-page/

    4433 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.