Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Widgets /

Discuss SilverStripe Widgets.

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

HTMLTextField in Widget


Go to End
Reply


16 Posts   4636 Views

Avatar
MarijnKampf

Community Member, 164 Posts

9 October 2010 at 4:23am

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")
      );
   }
}

?>

Avatar
swaiba

Forum Moderator, 1799 Posts

9 October 2010 at 5:38am

Edited: 09/10/2010 5:39am

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")'

Avatar
x75

Community Member, 42 Posts

22 October 2010 at 2:55am

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

Avatar
MarijnKampf

Community Member, 164 Posts

22 October 2010 at 7:49pm

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.

Avatar
Nivanka

Community Member, 397 Posts

19 November 2010 at 1:32pm

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!

Avatar
MarijnKampf

Community Member, 164 Posts

10 February 2011 at 1:43am

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.

Avatar
swaiba

Forum Moderator, 1799 Posts

10 February 2011 at 11:06pm

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

Avatar
CHD

Community Member, 218 Posts

18 January 2012 at 11:13pm

Edited: 18/01/2012 11:21pm

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/

Go to Top