[Ur] <ctextinput source={s} /> looses input focus after every keypress

Sergey Mironov grrwlf at gmail.com
Mon Apr 3 09:56:55 EDT 2017


Luckily, I actually don't need to update the HTML tree every time user
presses a  button, but only in case of Enter was pressed. In my case,
splitting the signal in two parts has solved the problem. Here is the
complete code, for reference.

Regards,
Sergey

(* modifiable label  *)
fun modlabel (t:string) (edit:string -> transaction unit) : xbody =
  <xml>
  <active code={
    smode <- source True;
    st_label <- source t;
    st_edit <- source t;
    cid <- fresh;
    return
    <xml>
      <dyn signal={
        t <- signal st_label;
        mode <- signal smode;
        return (case mode of
          |True => <xml>
              <span>
              <span>{[t]}</span>
              <button onclick={fn _ =>
                set smode False;
                return {}
              }>
                <span class="glyphicon glyphicon-edit"/>
              </button>
              </span>
            </xml>
          |False =>
            <xml>
              (* input control *)
              <ctextbox id={cid} source={st_edit} onkeypress={fn ev =>
                case ev.KeyCode = 13 of
                  |True => (
                    t <- get st_edit;
                    rpc(edit t);
                    set smode True;
                    set st_label t;
                    return {})
                  |False => (return {})
                }/>
            </xml>)
      }/>
    </xml>
  }/>
  </xml>

2017-04-03 16:50 GMT+03:00 Adam Chlipala <adamc at csail.mit.edu>:
> Yeah, sounds like there's no easy solution, unless you realize that the
> <dyn> dependency is spurious.  You could try breaking it into multiple
> smaller <dyn>s, maybe with some nested inside of others.
>
>
> On 04/03/2017 09:33 AM, Sergey Mironov wrote:
>>
>> Hm! The original code is sketched below. I am not interested in
>> catching every event from <ctextbox> but the code expresses exactly
>> this, so you are right, Thanks!
>>
>>
>> Regards,
>> Sergey
>>
>> PS by ctextinput I meant ctextbox
>>
>> fun editable (t:string) (upd:string->transaction unit) =
>>    <xml><active code={
>>       st <- source t;
>>       se <- source False; (*edit mode*)
>>
>>       ...
>>
>>       return <xml>
>>         <dyn signal={
>>           t <- signal st;
>>           e <- signal se;
>>
>>           return
>>           <xml>
>>
>>            <ctextbox signal={t} onkeypress={... v <- get t; rpc(upd v);
>> ... } />
>>
>>            </xml>
>>
>>         }/>
>>       </xml>
>>     }/>
>>     </xml>
>>
>> 2017-04-03 15:02 GMT+03:00 Adam Chlipala <adamc at csail.mit.edu>:
>>>
>>> Is the control inside a <dyn> whose value is affected by a source that
>>> every
>>> keypress updates? Focus is expected to go away every time a dynamic
>>> subtree
>>> needs to be rebuilt.
>>>
>>> On 04/03/2017 06:38 AM, Sergey Mironov wrote:
>>>>
>>>> Just found a strange issue regarding <ctextinput>. If used with
>>>> source={s} attribute set, the control looses input focus after every
>>>> keypress event. Removing source={s} brings back the correct behavior.
>>>> Is it a known issue?
>>>>
>>>> As a workaround, I tried <ctextinput id={cid} source={s}
>>>> onkeypress={fn _ => giveFocus cid} /> with no improvement.
>>>>
>>>> I'm using urweb-20170105 and firefox(nighty)-49.0
>>>
>>>
>>> _______________________________________________
>>> Ur mailing list
>>> Ur at impredicative.com
>>> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>>
>> _______________________________________________
>> Ur mailing list
>> Ur at impredicative.com
>> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
>
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur



More information about the Ur mailing list