Action on center text button

2

Someone could help me as I could do so when when I type any text into an input, there I have a button on top of my input where I want to center that typed text. Could someone help me how can I do it?

Here's the button I want you to do the action on (how to center my text):

<p:commandLink id="btn_close_users_modal33"
               styleClass="btn btn-default" action="">
    <i class="fa  fa-align-center fa-fw" />
</p:commandLink>

And here is my input when I type the text, I want to select what was typed and click the button to do the action of centering the text:

 <h:inputText value="#{frameBean.editorText1}" autocomplete="off"
              styleClass="form-control" tabindex="0"/>
    
asked by anonymous 15.06.2015 / 20:19

1 answer

0

You can use jQuery to add the text-center of Bootstrap class to input .

For example:

JavaScript and jQuery

<script>
    function centralizar(){
        $(".input-centralizar").addClass("text-center");
    }
<script>

I used .input-centralizar which represents the input that has this CSS class. I used CSS class, in this example, because it may be that your <h:form> is not with prependId="false" , because when it is true (default) all child elements of this form receive id form automatically makes it impractical to get the element by its id .

The action link

<p:commandLink id="btn_close_users_modal33" onclick="centralizar()"
           styleClass="btn btn-default" action="">
    <i class="fa  fa-align-center fa-fw" />
</p:commandLink>

<h:inputText value="#{frameBean.editorText1}" autocomplete="off"
          styleClass="form-control input-centralizar" tabindex="0"/>
    
15.06.2015 / 20:40