Kevin Yang
Kevin Yang

Reputation: 245

set focus to rich:editor in a rich:modalPanel when the modal panel popup

I have a very simple popup window with a rich editor:

<rich:modalPanel id="commentFormPanel" width="640" height="480">
    <f:facet name="header">
        <h:panelGroup>Comment</h:panelGroup>
    </f:facet>
    <h:form id="commentForm">
        <rich:editor id="commentContent" width="620" height="440"
            theme="simple" viewMode="visual"
            value="#{commentHome.content}" />
    </h:form>
</rich:modalPanel>

Is it possible to set focus in the rich:editor when the modal panel pops up?

Someone suggested to use this:

tinyMCE.execCommand('mceFocus',false,'commentForm:commentContent');

I tried but it did not work. Does anyone have a solution? Thanks.

Update:

I tried a few things:

a).

<rich:editor id="commentContent" width="620" height="440"
    theme="simple" viewMode="visual">
    <f:param name="auto_focus" value="commentForm:commentContent" />
</rich:editor>

b).

<rich:modalPanel onshow="tinyMCE.get('commentForm:commentContent').focus();">

both did not work.

Upvotes: 0

Views: 2101

Answers (3)

user2164333
user2164333

Reputation: 1

Add Tag domElementAttachment="parent" to rich:modalPanel

Upvotes: 0

Mark Wen
Mark Wen

Reputation: 26

This will work:

        <rich:editor id="commentContent" width="620" height="440"
            theme="simple" viewMode="visual" useSeamText="false"
            value="#{commentHome.content}"
            oninit="setTimeout( function() { tinyMCE.execCommand('mceFocus',false,'commentForm:commentContentTextArea'); }, 1);" />

Upvotes: 1

Ramin Mir.
Ramin Mir.

Reputation: 784

<rich:jQuery query="focus().select()" selector="#commentContent" name="focusInput"/>

<script>
  focusInput();
</script>

Upvotes: 0

Related Questions