How do I create a responsive Rich Text Editor item on a page?
Simple question and answer, right? Well, you'd be wrong. While we pride ourselves on the responsive user interfaces that you can easily create with Oracle Application Express (APEX), unfortunately, the item type of Rich Text Editor is not responsive, out of the box.
So - I did what all smart people do, and I reached out to the Oracle APEX Development team, in this case, the ever-intelligent Carsten Czarski. And in a few minutes, he showed me exactly what I needed to do.
- Open up Application Builder, and in Page Designer, edit the page with the Rich Text Editor item. In my example, my Rich Text Editor page item name is P3_RESUME.
- Navigate to the attributes of the Rich Text Editor item, and in the Advanced section, enter the following code in the "JavaScript Initialization Code" attribute:
function (o) { o.width = $("#P3_RESUME").closest(".t-Form-inputContainer").width() - 5; o.height = 300; // Specify your desired item height, in pixels return o; }
This code determines the width of the region container of the item, subtracts 5, and returns the object initialized to this size. This will take care of the Rich Text Editor when the page is initially displayed. But it won't handle the case when the browser is resized. To handle that case, we'll need to add a dynamic action. - Click the Dynamic Actions sub-tab in Page designer (the lightning bolt)
- Select Events in the upper-left, right-click your mouse and choose "Create Dynamic Action".
- In the attributes, enter "Resize" for Name, and select "Resize" for the Event.
- Select the True action of the dynamic action (it should be "Show"). Change the Action to "Execute JavaScript Code".
- In the Code attribute, enter the code:
CKEDITOR.instances.P3_RESUME.resize( $("#P3_RESUME").closest(".t-Form-inputContainer").width() - 5, 300);
This is an absolute reference to the Rich Text Editor item on the page, named P3_RESUME. And like the code before, this will determine what the width is of the container of the item, subtract 5 from it, and invoke the resize() method of the Rich Text Editor (CK Editor) element.
Obviously, this item type (like all others) should be responsive, out of the box. And Carsten is looking at this for the next version of APEX. In the meantime, if you're using Universal Theme with Oracle APEX 5.1, all it takes is a tiny amount of JavaScript to get a responsive Rich Text Editor.