You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Alex Grant (JIRA)" <ji...@apache.org> on 2010/10/05 03:49:32 UTC

[jira] Created: (WICKET-3093) Self-updating AutoCompleteTextField moves focus to start of field in IE only

Self-updating AutoCompleteTextField moves focus to start of field in IE only
----------------------------------------------------------------------------

                 Key: WICKET-3093
                 URL: https://issues.apache.org/jira/browse/WICKET-3093
             Project: Wicket
          Issue Type: Bug
    Affects Versions: 1.4.12
            Reporter: Alex Grant
            Priority: Minor


I have an AutoCompleteTextField that has a AjaxFormSubmitBehavior("onchange") attached so that we can canonicalise the value (eg correct the case) automatically. In IE only, when you pause long enough to trigger the AjaxFormSubmitBehavior, the cursor moves to the start of the text field, so if you type "123" slowly you may be "312".

This is only an issue in IE as it is caused by WICKET-2279 - if I remove the javascript added for that bug the problem goes away.

The problem can also be solved by changing AjaxFormSubmitBehavior("onchange") to AjaxFormSubmitBehavior("onblur"), but I still consider it a bug given it only occurs in IE - Firefox and Chrome behave correctly no matter what you do.

Also, since the javascript added in WICKET-2279 starts with the comment "// hack for a focus issue in IE, WICKET-2279" I figured you'd like to know about any quirky behaviour it causes.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WICKET-3093) Self-updating AutoCompleteTextField moves focus to start of field in IE only

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3093?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-3093.
-----------------------------------

    Resolution: Won't Fix
      Assignee: Igor Vaynberg

even if it did work i wouldnt do it this way. you are replacing the dom element the user is currently using from under them. things like selections, etc will be lost. i would rather do this in onblur like you mentioned.

that said you can meticate it somewhat

to start instead of replacing the entire dom element of the autocomplete update the normalized value only:
{code}
	// changing this to "onblur" fixes the problem
		autocomplete.add(new AjaxFormSubmitBehavior("onchange") {
			@Override
			protected void onSubmit(AjaxRequestTarget target) {
				target.focusComponent(null);
				String corrected = autocomplete.getDefaultModelObjectAsString();
				target.appendJavascript("(function() { var f=document.getElementById('"
						+ autocomplete.getMarkupId()
						+ "'); f.value='"+ corrected	+ "';})()");
			}
		});
{code}

next you can prevent caret jumping by using some javascript

{code}
<script type="text/javascript">
		function getCaretPos(el) {
			var rng, ii=-1;
			if(typeof el.selectionStart=="number") {
				ii=el.selectionStart;
			} else if (document.selection && el.createTextRange){
				rng=document.selection.createRange();
				rng.collapse(true);
				rng.moveStart("character", -el.value.length);
				ii=rng.text.length;
			}
			return ii;
		}
	   function setCaretPos(ctrl, pos){
		if(ctrl.setSelectionRange)
		{
			ctrl.focus();
			ctrl.setSelectionRange(pos,pos);
		}
		else if (ctrl.createTextRange) {
			var range = ctrl.createTextRange();
			range.collapse(true);
			range.moveEnd('character', pos);
			range.moveStart('character', pos);
			range.select();
		}
   		}
		</script>

{code}
{code}
	// changing this to "onblur" fixes the problem
		autocomplete.add(new AjaxFormSubmitBehavior("onchange") {
			@Override
			protected void onSubmit(AjaxRequestTarget target) {
				target.focusComponent(null);
				String corrected = autocomplete.getDefaultModelObjectAsString();
				target.appendJavascript("(function() { var f=document.getElementById('"
						+ autocomplete.getMarkupId()
						+ "'); var c=getCaretPos(f); f.value='"
						+ corrected
						+ "'; setCaretPos(f, c);})()");
			}

		});
{code}

the best way to do this, if you must correct in real time is to write the conversion on the client side in javascript, that way there is no lag.

> Self-updating AutoCompleteTextField moves focus to start of field in IE only
> ----------------------------------------------------------------------------
>
>                 Key: WICKET-3093
>                 URL: https://issues.apache.org/jira/browse/WICKET-3093
>             Project: Wicket
>          Issue Type: Bug
>    Affects Versions: 1.4.12
>            Reporter: Alex Grant
>            Assignee: Igor Vaynberg
>            Priority: Minor
>         Attachments: WICKET-3093-autocomplete.zip
>
>
> I have an AutoCompleteTextField that has a AjaxFormSubmitBehavior("onchange") attached so that we can canonicalise the value (eg correct the case) automatically. In IE only, when you pause long enough to trigger the AjaxFormSubmitBehavior, the cursor moves to the start of the text field, so if you type "123" slowly you may be "312".
> This is only an issue in IE as it is caused by WICKET-2279 - if I remove the javascript added for that bug the problem goes away.
> The problem can also be solved by changing AjaxFormSubmitBehavior("onchange") to AjaxFormSubmitBehavior("onblur"), but I still consider it a bug given it only occurs in IE - Firefox and Chrome behave correctly no matter what you do.
> Also, since the javascript added in WICKET-2279 starts with the comment "// hack for a focus issue in IE, WICKET-2279" I figured you'd like to know about any quirky behaviour it causes.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WICKET-3093) Self-updating AutoCompleteTextField moves focus to start of field in IE only

Posted by "Alex Grant (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3093?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Grant updated WICKET-3093:
-------------------------------

    Attachment: WICKET-3093-autocomplete.zip

Added quickstart.

> Self-updating AutoCompleteTextField moves focus to start of field in IE only
> ----------------------------------------------------------------------------
>
>                 Key: WICKET-3093
>                 URL: https://issues.apache.org/jira/browse/WICKET-3093
>             Project: Wicket
>          Issue Type: Bug
>    Affects Versions: 1.4.12
>            Reporter: Alex Grant
>            Priority: Minor
>         Attachments: WICKET-3093-autocomplete.zip
>
>
> I have an AutoCompleteTextField that has a AjaxFormSubmitBehavior("onchange") attached so that we can canonicalise the value (eg correct the case) automatically. In IE only, when you pause long enough to trigger the AjaxFormSubmitBehavior, the cursor moves to the start of the text field, so if you type "123" slowly you may be "312".
> This is only an issue in IE as it is caused by WICKET-2279 - if I remove the javascript added for that bug the problem goes away.
> The problem can also be solved by changing AjaxFormSubmitBehavior("onchange") to AjaxFormSubmitBehavior("onblur"), but I still consider it a bug given it only occurs in IE - Firefox and Chrome behave correctly no matter what you do.
> Also, since the javascript added in WICKET-2279 starts with the comment "// hack for a focus issue in IE, WICKET-2279" I figured you'd like to know about any quirky behaviour it causes.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.