Boolean Attr

30 views
Skip to first unread message

Mathieu Leclaire

unread,
Jan 14, 2015, 11:32:24 AM1/14/15
to scal...@googlegroups.com
Hi,
I try to set the autofocus Attr on an input.
In the html documentation the autofocus is not related to a pair: you just define as "autofocus":
<input type="text" name="fname" autofocus>

But autoinput in scalatags requires a pair. So I tried:
input(autofocus := "true")
input(autofocus := true)

Buc rone on them works:
The html results is always: <input autofocus="">.
Do you know how to achieve this ?

Reid Spencer

unread,
Jan 14, 2015, 1:33:21 PM1/14/15
to Mathieu Leclaire, scal...@googlegroups.com
autoinput is a boolean attribute which means it doesn’t need a value. If it requires one in an input tag, that’s a bug in scalatags. OTOH, you could set the value to “autofocus” which should cause it to appear with a value. 

--
You received this message because you are subscribed to the Google Groups "Scalatags" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatags+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Haoyi Li

unread,
Jan 15, 2015, 2:15:07 PM1/15/15
to Reid Spencer, Mathieu Leclaire, scal...@googlegroups.com
Might well be a bug in scalatags, but haven't had time to reproduce and debug, sorry...

Mathieu Leclaire

unread,
Jan 16, 2015, 5:12:19 AM1/16/15
to Haoyi Li, Reid Spencer, scal...@googlegroups.com
Well, I am not sure of what I am supposed to get with the autofocus. In my mind, when the page is loaded the focus is on this element. In particular for an input: the input is ready to receive new inputs without selecting it with the mouse.
But when I try the simple <input autofocus /> in a jsfiddle, the input in not focused ... It is exactly the same with <input autofocus="autofocus" />.
http://jsfiddle.net/cmw0qbz5/
-- 
Be green, keep it on the screen
Faites bonne impression et imprimez seulement au besoin! 

Reid Spencer

unread,
Jan 16, 2015, 5:27:05 AM1/16/15
to Mathieu Leclaire, Haoyi Li, scal...@googlegroups.com
Your jsfiddle works for me if I make it have valid HTML. See: http://jsfiddle.net/cmw0qbz5/2/

But that’s not really the point of this thread. We want to make sure that the “autofocus” attribute in scalawags works.  My version of scalatags.generic.Attrs contains this:
/**
* This Boolean attribute lets you specify that a form control should have
* input focus when the page loads, unless the user overrides it, for example
* by typing in a different control. Only one form element in a document can
* have the autofocus attribute, which is a Boolean. It cannot be applied if
* the type attribute is set to hidden (that is, you cannot automatically set
* focus to a hidden control).
*
* MDN
*/
val autofocus = "autofocus".attr := "autofocus"
Note that autofocus here is defined WITH a value (“autofocus”) so it shouldn’t need one in your code. You should be able to do, simply:

input(type=“text”,autofocus)

Does this not work for you?

Reid.

Mathieu Leclaire

unread,
Jan 16, 2015, 6:02:32 AM1/16/15
to Reid Spencer, Haoyi Li, scal...@googlegroups.com
It's the point, because I want to know what I am supposed to get :) !
Actually your jsfiddle works on chrome but not on firefox ... I suppose you use chrome, right ?

And if I try my scalatags code on chrome, the focus is properly set.
So the issue seems to be that the autofocus attribute does not work on firefox ...

Reid Spencer

unread,
Jan 16, 2015, 6:08:49 AM1/16/15
to Mathieu Leclaire, Haoyi Li, scal...@googlegroups.com
Yes, I used Chrome. No, it doesn’t work in Firefox. Yes, that can even be shown in a w3schools example: http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_input_autofocus 

And, no, this is not the right forum to discuss browser bugs. 

Mathieu Leclaire

unread,
Jan 16, 2015, 6:21:05 AM1/16/15
to Reid Spencer, Haoyi Li, scal...@googlegroups.com
Well, I would not have opened this discussion if I had known the origin of the problem ...
Reply all
Reply to author
Forward
0 new messages