[Ur] More questions: sql_injectable, reactivity and interaction with CSS
Adam Chlipala
adamc at impredicative.com
Tue Jan 12 08:22:33 EST 2010
Artyom Shalkhakov wrote:
> Here's what I do:
>
>> fun editable () =
>> m<- source False; (* mode: editing or viewing *)
>> t<- source "click to edit";
>> let
>> fun act () =
>> m'<- signal m;
>> return (if m' then
>> <xml><ctextbox source={t}/><button onclick={set m False}/></xml>
>> else<xml><dyn signal={t'<- signal t; return (cdata t')}/></xml>
>> in
>> return<xml><body>
>> <div onclick={m'<- get m; if not m' then set m True else return ()}>
>> <dyn signal={act ()}/>
>> </div>
>> </body></xml>
>> end
>>
> I think it should work but actually clicking on the button doesn't
> revert the mode from editing to viewing. Is there something I do
> wrong?
>
Yes, and in fact it's just a simple misunderstanding, based on semantics
inherited from HTML/JavaScript. The <button> you create is inside the
<div> with an 'onclick' attribute. Thus, when you click on the button,
_both_ 'onclick' handlers run. The <div>'s handler cancels the effect
of the <button>'s handler! (You can add some [alert] calls to forcibly
pause the process at different points; this lets you see the text appear
and then disappear again.)
More information about the Ur
mailing list