Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4718

focusElement form attribute not working

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.3.24, 2.5.5
    • Fix Version/s: 2.5.8
    • Component/s: None
    • Labels:
      None
    • Environment:

      internet explorer
      chrome

      Description

      I cannot get the focusElement attribute on the form tag to work. I've tried it in both IE and chrome and in neither case will the text field I want to focus when the page loads do so.

      Here is the html for the form I'm trying to do this with:

      <s:form action="ViewSubscriber" method="GET" cssClass="form-group"
              focusElement="subscriberListAutocomplete">
          <div class="input-group">
              <s:textfield name="subscriberName" 
                           id="subscriberListAutocomplete" 
                           cssClass="subscriberListAutocomplete form-control"
                           placeholder="Subscriber Name"
                           tabindex="1"/>
              <span class="input-group-btn">
                  <s:submit value="View Subscriber" 
                            cssClass="btn btn-success"
                            tabindex="0"/>
              </span>
          </div>
      </s:form>
      

      If I change the textfield to a basic input element and use html's autofocus attribute, it works fine. I have no idea what else I can try on this.

        Activity

        Hide
        lukaszlenart Lukasz Lenart added a comment - - edited

        If you are using the Bootstrap plugin you can simply override its form-close.ftl template by creating a file template/bootstrap/form-close.ftl in your project (under resources or WEB-INF)

        <#include "/${parameters.templateDir}/bootstrap/control-close.ftl" />
        <#include "/${parameters.templateDir}/simple/form-close.ftl" />
        <script type="text/javascript">
            if (typeof jQuery != 'undefined') {
                if (typeof jQuery.fn.tooltip == 'function') {
                    jQuery('i.s2b_tooltip').tooltip();
                }
            }
        </script>
        
        <#if parameters.focusElement??>
        <script type="text/javascript">
            if (typeof jQuery != 'undefined') {
                jQuery(document).ready(function() {
                    var element  = jQuery("#${parameters.focusElement?html}");
                    if(element) {
                        element.focus();
                    }
                });
            }
        </script>
        </#if>
        
        Show
        lukaszlenart Lukasz Lenart added a comment - - edited If you are using the Bootstrap plugin you can simply override its form-close.ftl template by creating a file template/bootstrap/form-close.ftl in your project (under resources or WEB-INF ) <#include "/${parameters.templateDir}/bootstrap/control-close.ftl" /> <#include "/${parameters.templateDir}/simple/form-close.ftl" /> <script type= "text/javascript" > if (typeof jQuery != 'undefined') { if (typeof jQuery.fn.tooltip == 'function') { jQuery('i.s2b_tooltip').tooltip(); } } </script> <#if parameters.focusElement??> <script type= "text/javascript" > if (typeof jQuery != 'undefined') { jQuery(document).ready(function() { var element = jQuery( "#${parameters.focusElement?html}" ); if(element) { element.focus(); } }); } </script> </#if>
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        <constant name="struts.serve.static" value="true" />?

        Show
        lukaszlenart Lukasz Lenart added a comment - <constant name="struts.serve.static" value="true" /> ?
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        Do you use xhtml theme? Did you include Struts JS helper?

        Show
        lukaszlenart Lukasz Lenart added a comment - Do you use xhtml theme? Did you include Struts JS helper?

          People

          • Assignee:
            lukaszlenart Lukasz Lenart
            Reporter:
            cdavis Chad Davis
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development