Handling FocusOnLoad and "nice" handling of input field at the same time?

30 views
Skip to first unread message

Kenneth McDonald

unread,
Jul 29, 2011, 3:57:54 PM7/29/11
to lif...@googlegroups.com
While reworking some older code, I came up with this as part of a snippet for rendering and processing a form:

"#email *" #> FocusOnLoad(<input type="text" name="username"/>) &
"name=username" #> SHtml.onSubmit(username = _) &

So, I'm trying to ensure the username field has the cursor when the page is loaded. I'm also trying to make sure the local variable "username" is assigned the value of the username field when the form is submitted.

Unfortunately, this doesn't work, no doubt because the <input type="text" name="username"/> is not actually part of the page being transformed when "name=username" #> SHtml.onSubmit(username = _) is executed. I've looked at FocusOnLoad and it needs an element--I can't get away with just giving it an id or something. So I suppose I need to put <input type="text" name="username"/> into the original form, get rid of FocusOnLoad, and figure out some other way to set the focus after the page loads. Any suggestions on the cleanest way to do this?

Thanks,
Ken

Diego Medina

unread,
Jul 29, 2011, 4:03:04 PM7/29/11
to lif...@googlegroups.com
Hi,

On Fri, Jul 29, 2011 at 3:57 PM, Kenneth McDonald <ykke...@gmail.com> wrote:
> While reworking some older code, I came up with this as part of a snippet
> for rendering and processing a form:
> "#email *" #> FocusOnLoad(<input type="text" name="username"/>) &
> "name=username" #> SHtml.onSubmit(username = _) &

try this:

"name=username" #> SHtml.onSubmit(username = _) andThen


"#email *" #> FocusOnLoad(<input type="text" name="username"/>) &

if it works, I'll explain why :)
Well, I should just say it now, the andThen basically separates the
two replacements and makes sure that the first one is done before the
second one. if you separate them by a simple & , I *think* the order
is not guaranteed.

Hope it works

Diego

> So, I'm trying to ensure the username field has the cursor when the page is
> loaded. I'm also trying to make sure the local variable "username" is
> assigned the value of the username field when the form is submitted.
> Unfortunately, this doesn't work, no doubt because the <input type="text"
> name="username"/> is not actually part of the page being transformed
> when "name=username" #> SHtml.onSubmit(username = _) is executed. I've
> looked at FocusOnLoad and it needs an element--I can't get away with just
> giving it an id or something. So I suppose I need to put <input type="text"
> name="username"/> into the original form, get rid of FocusOnLoad, and figure
> out some other way to set the focus after the page loads. Any suggestions on
> the cleanest way to do this?
> Thanks,
> Ken
>

> --
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/liftweb/-/nkbD2pcNJcIJ.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to
> liftweb+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>

--
Diego Medina
Web Developer
(305) 788-4954
di...@fmpwizard.com
http://www.fmpwizard.com

Kenneth McDonald

unread,
Jul 29, 2011, 5:57:47 PM7/29/11
to lif...@googlegroups.com

"name=username" #> SHtml.onSubmit(username = _) andThen
"#email *" #> FocusOnLoad(<input type="text" name="username"/>) &


that doesn't work, but this:

"#email *" #> FocusOnLoad(<input type="text" name="username"/>) andThen
"name=username" #> SHtml.onSubmit(username = _) &

does! Makes sense when you think about it, in the first case there's no "name=username" attribute to match to.

Thanks for the pointer! That's certainly a lot easier than doing it any other way, plus I can see multiple uses for andThen...

Ken 

Diego Medina

unread,
Jul 29, 2011, 6:19:21 PM7/29/11
to lif...@googlegroups.com

Great!

Sent from my cell
Diego

> --
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/liftweb/-/lCYAPj1XuZwJ.
Reply all
Reply to author
Forward
0 new messages