Append text to editor with a command button

UI Components for JSF
Post Reply
crazy.8
Posts: 13
Joined: 18 Feb 2011, 18:37

19 May 2011, 18:21

I want to have a commandButton that will insert a text at the current cursor in the editor for a macro that I will parse on the back end. I want to insert #SomeMaco# and have it show up in the editor while they are finishing the email, is this possible?

Thanks!

Drake
Posts: 44
Joined: 25 Jan 2011, 10:59

18 Jul 2011, 16:18

I'd like this feature too!

I see that p:editor is based on CLEditor,
but in this section http://premiumsoftware.net/cleditor/doc ... itorMethod I couldn't find an "insertAtCursor" method or something like that.

A nice to have feature could be Drag&Drop placeholders ;)
WildFly 10.1.0 Final, Mojarra 2.2.15 PrimeFaces 6.2

Drake
Posts: 44
Joined: 25 Jan 2011, 10:59

11 Oct 2011, 10:17

Finally I solved it.
I created n buttons in a div with id "availablePlaceholders".
Then, I used this script to add .click() behaviour to the buttons.

Code: Select all

<h:outputScript target="body">
            jQuery(PrimeFaces.escapeClientId('availablePlaceholders button')).click(function() {
            var token = jQuery(this).attr('id');
            editorHtml.editor.focus();
            setTimeout(function() {
            editorHtml.editor.execCommand('inserthtml', '{ ' + token + ' }', false);
            }, 0);
            return false
            });
       </h:outputScript>
Note: editorHtml is the widgetVar of p:editor.

Clicking a button with id "hello", inserts "{ hello}" in the p:editor at cursor position.

Hope it helps
WildFly 10.1.0 Final, Mojarra 2.2.15 PrimeFaces 6.2

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

11 Oct 2011, 10:44

Great, thx for sharing with community.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 50 guests