Focus

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Focus

DiegoLont
Hi all,

I must miss very simple, because I fail to set the focus of my element. I tried stripping my component, but still it does do nothing. I think the problem lies in the generated javascript.
This is the code that I use to generate it:
renderContentOn: canvas

        | textInput |
        textInput := canvas textInput.
        canvas document addLoadScript: 'document.getElementById("', textInput ensureId ,'").focus()'.
        textInput on: #userid of: self
...
And this is the resulting javascript:
        /*<![CDATA[*/function onLoad(){"document.getElementById(\"id1\").focus()";};/*]]>*/

When I look at this javascript, I see that my parameter (“id”) is encoded. This is probably why it does not find the element indicated …

Does anyone know how I can solve this?

Cheers,
Diego_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Focus

Sven Van Caekenberghe-2
I do it like this:

renderJavaScriptOn: html
        | target |
        target := self username
                ifNil: [ 'form #username' ]
                ifNotNil: [ 'form #password' ].
        html script: (html jQuery: target) triggerFocus

for a login component (the focus is set on the username field unless it is filled in, in which case the focus goes to the password field).

On 02 Jun 2014, at 14:27, Diego Lont <[hidden email]> wrote:

> Hi all,
>
> I must miss very simple, because I fail to set the focus of my element. I tried stripping my component, but still it does do nothing. I think the problem lies in the generated javascript.
> This is the code that I use to generate it:
> renderContentOn: canvas
> …
> | textInput |
> textInput := canvas textInput.
> canvas document addLoadScript: 'document.getElementById("', textInput ensureId ,'").focus()'.
> textInput on: #userid of: self
> ...
> And this is the resulting javascript:
> /*<![CDATA[*/function onLoad(){"document.getElementById(\"id1\").focus()";};/*]]>*/
>
> When I look at this javascript, I see that my parameter (“id”) is encoded. This is probably why it does not find the element indicated …
>
> Does anyone know how I can solve this?
>
> Cheers,
> Diego_______________________________________________
> seaside-dev mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Focus

philippeback
On Mon, Jun 2, 2014 at 2:32 PM, Sven Van Caekenberghe <[hidden email]> wrote:
I do it like this:

renderJavaScriptOn: html
        | target |
        target := self username
                ifNil: [ 'form #username' ]
                ifNotNil: [ 'form #password' ].
        html script: (html jQuery: target) triggerFocus

for a login component (the focus is set on the username field unless it is filled in, in which case the focus goes to the password field).

jQuery indeed. Now, script: will do that in place. So, if you are loading things at the bottom of the script, it will fail.

I wondered what is your practice regarding those things.

Now, I am putting things in <head> so that everything works as advertised.

Phil



On 02 Jun 2014, at 14:27, Diego Lont <[hidden email]> wrote:

> Hi all,
>
> I must miss very simple, because I fail to set the focus of my element. I tried stripping my component, but still it does do nothing. I think the problem lies in the generated javascript.
> This is the code that I use to generate it:
> renderContentOn: canvas
> …
>       | textInput |
>       textInput := canvas textInput.
>       canvas document addLoadScript: 'document.getElementById("', textInput ensureId ,'").focus()'.
>       textInput on: #userid of: self
> ...
> And this is the resulting javascript:
>       /*<![CDATA[*/function onLoad(){"document.getElementById(\"id1\").focus()";};/*]]>*/
>
> When I look at this javascript, I see that my parameter (“id”) is encoded. This is probably why it does not find the element indicated …
>
> Does anyone know how I can solve this?
>
> Cheers,
> Diego_______________________________________________
> seaside-dev mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev


_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Focus

Sven Van Caekenberghe-2

On 02 Jun 2014, at 14:42, [hidden email] wrote:

> jQuery indeed. Now, script: will do that in place. So, if you are loading things at the bottom of the script, it will fail.
>
> I wondered what is your practice regarding those things.
>
> Now, I am putting things in <head> so that everything works as advertised.

I am not sure what you mean by 'fail' but there is always #ready: as well. But I am no expert...

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Focus

DiegoLont
In reply to this post by Sven Van Caekenberghe-2
Thanks Sven,

Works like a charm.

But isn’t it a bit strange that quotes are translated when rendering javascript? We should be able to simply input a script as a string shouldn’t we? Should we add a type that is not translated? Like we have canvas html: ‘<div>we can do it like this also</div>’. Or do we have this somewhere?

On 02 Jun 2014, at 14:32, Sven Van Caekenberghe <[hidden email]> wrote:

> I do it like this:
>
> renderJavaScriptOn: html
> | target |
> target := self username
> ifNil: [ 'form #username' ]
> ifNotNil: [ 'form #password' ].
> html script: (html jQuery: target) triggerFocus
>
> for a login component (the focus is set on the username field unless it is filled in, in which case the focus goes to the password field).
>
> On 02 Jun 2014, at 14:27, Diego Lont <[hidden email]> wrote:
>
>> Hi all,
>>
>> I must miss very simple, because I fail to set the focus of my element. I tried stripping my component, but still it does do nothing. I think the problem lies in the generated javascript.
>> This is the code that I use to generate it:
>> renderContentOn: canvas
>> …
>> | textInput |
>> textInput := canvas textInput.
>> canvas document addLoadScript: 'document.getElementById("', textInput ensureId ,'").focus()'.
>> textInput on: #userid of: self
>> ...
>> And this is the resulting javascript:
>> /*<![CDATA[*/function onLoad(){"document.getElementById(\"id1\").focus()";};/*]]>*/
>>
>> When I look at this javascript, I see that my parameter (“id”) is encoded. This is probably why it does not find the element indicated …
>>
>> Does anyone know how I can solve this?
>>
>> Cheers,
>> Diego_______________________________________________
>> seaside-dev mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
>
> _______________________________________________
> seaside-dev mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: Focus

Philippe Marschall
In reply to this post by DiegoLont
On Mon, Jun 2, 2014 at 2:27 PM, Diego Lont <[hidden email]> wrote:

> Hi all,
>
> I must miss very simple, because I fail to set the focus of my element. I tried stripping my component, but still it does do nothing. I think the problem lies in the generated javascript.
> This is the code that I use to generate it:
> renderContentOn: canvas
> …
>         | textInput |
>         textInput := canvas textInput.
>         canvas document addLoadScript: 'document.getElementById("', textInput ensureId ,'").focus()'.
>         textInput on: #userid of: self
> ...
> And this is the resulting javascript:
>         /*<![CDATA[*/function onLoad(){"document.getElementById(\"id1\").focus()";};/*]]>*/
>
> When I look at this javascript, I see that my parameter (“id”) is encoded. This is probably why it does not find the element indicated …
>
> Does anyone know how I can solve this?

If you have the same browser support policy as Google (only IE 10 and
11) then you can use the autofocus attribute.

Cheers
Philippe
_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev