W3C home > Mailing lists > Public > www-international@w3.org > January to March 2011

Re: set input.value when input element has composition string

From: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Date: Tue, 01 Mar 2011 17:18:57 +0900
Message-ID: <4D6CABF1.1020709@ga2.so-net.ne.jp>
To: "Kang-Hao (Kenny) Lu" <kennyluck@w3.org>
CC: WHAT Working Group <whatwg@whatwg.org>, WWW International <www-international@w3.org>, WebApps Working Group <public-webapps@w3.org>
Hi, Kang-Hao.

On 2011/02/28 21:31, Kang-Hao (Kenny) Lu wrote:
> Hello Makoto,
> (Cc+ public-webapps)
>
> (11/02/25 15:16), Makoto Kato wrote:
>> Hi,
>>
>> This is simple sample.  This behavior is different on all web browsers
>> when input element has composition/preedit string for IME.
> A relevant question here, I think, is where the cursor should go when
> the value of the text box is set by script. For Safari5, it always goes
> to the end when the value is set. For FF4.0b11, the cursor stays in
> previous position when the value to be set is the same and goes to the
> end when the value is different. Is this a known incompatibility? I find
> the behavior of FF quite strange.

On Safari 5, even if textbox has IME composition string, text into 
textbox can be replaced by DOM/script.  But other browser's behaviors 
are different, and this is no specification when textbox has composition 
string.  Although IE, Chrome and Opera keep composition string after 
value is replaced by DOM, each behavior is different.

This is the result for this test on each browsers.  When textbox has IME 
composition string such as ABCDEFG, then script (textbox.value = "123";) 
is called, textbox becomes...

1. "123ABCDEFG" (ABCDEFG keeps composition state and caret is after G).
2. "123" (composition string is removed).
3. "ABCDEFG" (ABCDEFG keeps composition state and caret is after G).

Which behavior is right?  1 is Opera 11, 2 is Safari 5, and 3 is Chrome 
10 and IE9.

Also, on Firefox/Gecko, since there is some bugs, key input cannot work 
until IME is turned off.  So to fix this, I am talking with Ehsan about 
right specification.  But there is no discussion about this 
specification/behavior at WHATWG.

>> If input element has composition string by IME, should it cancel
>> composition string and set value by script?  Or should it cancel
>> setting value since it has composition string?
> What makes sense to me is:
> 1. the cursor always goes to the end
> 2. the composition string goes with the cursor, which should not change.
>
> But I am not sure whether this is the right way to go.
>
> Cheers,
> Kenny
>>
>> <script>
>> function setvalue() {
>>    document.getElementById('test').value = "replaced";
>> }
>> </script>
>> <body onload="setTimeout('setvalue()',5000)">
>> <input type="text" id="test"/>
>> </body>
>>
>>
>> -- Makoto Kato
>>
-- Makoto Kato
Received on Tuesday, 1 March 2011 08:19:39 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 1 March 2011 08:19:41 GMT