getting focus on a repeated textarea after insert

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

getting focus on a repeated textarea after insert

dr.cw.ray
Hey all,
Just can't seem to get the right focus. I am adding a nodeset with
insert into a repeat. When  I click on the "add" label, I need the
focus to move down to the last textarea that was just added (instead
of just remaining on the "add" label). This is because I have a long
list and it is not convenient for the user to have to scroll or page
down a long list to get to the recently added post (textarea).  I'm
trying to use xforms-setfocus, but maybe that's the wrong approach--?

Here is my code snippet.

the xml instance structure is below; it is identical for the id="main"
instance and the id="inst2" instance ( "inst2" is just the dummy
instance I use for populating the "main" instance)

  <xf:instance id="inst2">
    <board xmlns="">
      <boardTitle/>
      <topic>
        <topicTitle>New</topicTitle>
        <post>
          <user>User</user>
          <date/>
          <content>content</content>
        </post>
      </topic>
    </board>
  </xf:instance>


Here is the insert action of my xforms-trigger with "add" label:

        <xf:action ev:event="DOMActivate">

            <xf:insert
               origin="instance('inst2')/topic/post"
               nodeset="post"
               at="post[position()=last()]"
               position="after" />

            <xf:setfocus control="position()=last()"/>

         </xf:action>

The "postition()=last()" was just the last thing I tried out of
several attempts. I also tried "repeatPost" and "post[position()=last
()]" and "content[position()=last()]" and "last()" and "index" and
"index[last()]" and I can't remember what else. I love xforms but this
is the one area of using xforms that I just can't seem to "get".


Here is the actual repeat that is being inserted into.  Notice that
the xf:textarea references the node "content" which is where I need
the focus to go, so that the form moves down to the bottom of the list
automatically.

         <xf:repeat nodeset="post" id="repeatPost">

            <xf:label>User</xf:label>
            <xf:output ref="user">
            <xf:output  value="concat(substring(./date,
6,2),'/',substring(./date,9,2),'/',
                substring(./date,1,4),' - ', substring(./date,12,5))"/
>

            <xf:textarea ref="content">
               <xf:setvalue ev:event="xforms-value-changed" ref="../
@pEdited" value="1"/>
            </xf:textarea>

         </xf:repeat>

Any thoughts?
_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: getting focus on a repeated textarea after insert

Dion Sole
On Aug 10, 5:20 am, "dr.cw.ray" <[hidden email]> wrote:

> Hey all,
> Just can't seem to get the right focus. I am adding a nodeset with
> insert into a repeat. When  I click on the "add" label, I need the
> focus to move down to the last textarea that was just added (instead
> of just remaining on the "add" label). This is because I have a long
> list and it is not convenient for the user to have to scroll or page
> down a long list to get to the recently added post (textarea).  I'm
> trying to use xforms-setfocus, but maybe that's the wrong approach--?
>
> Here is my code snippet.
>
> the xml instance structure is below; it is identical for the id="main"
> instance and the id="inst2" instance ( "inst2" is just the dummy
> instance I use for populating the "main" instance)
>
>   <xf:instance id="inst2">
>     <board xmlns="">
>       <boardTitle/>
>       <topic>
>         <topicTitle>New</topicTitle>
>         <post>
>           <user>User</user>
>           <date/>
>           <content>content</content>
>         </post>
>       </topic>
>     </board>
>   </xf:instance>
>
> Here is the insert action of my xforms-trigger with "add" label:
>
>         <xf:action ev:event="DOMActivate">
>
>             <xf:insert
>                origin="instance('inst2')/topic/post"
>                nodeset="post"
>                at="post[position()=last()]"
>                position="after" />
>
>             <xf:setfocus control="position()=last()"/>
>
>          </xf:action>
>
> The "postition()=last()" was just the last thing I tried out of
> several attempts. I also tried "repeatPost" and "post[position()=last
> ()]" and "content[position()=last()]" and "last()" and "index" and
> "index[last()]" and I can't remember what else. I love xforms but this
> is the one area of using xforms that I just can't seem to "get".
>
> Here is the actual repeat that is being inserted into.  Notice that
> the xf:textarea references the node "content" which is where I need
> the focus to go, so that the form moves down to the bottom of the list
> automatically.
>
>          <xf:repeat nodeset="post" id="repeatPost">
>
>             <xf:label>User</xf:label>
>             <xf:output ref="user">
>             <xf:output  value="concat(substring(./date,
> 6,2),'/',substring(./date,9,2),'/',
>                 substring(./date,1,4),' - ', substring(./date,12,5))"/
>
>
>
>             <xf:textarea ref="content">
>                <xf:setvalue ev:event="xforms-value-changed" ref="../
> @pEdited" value="1"/>
>             </xf:textarea>
>
>          </xf:repeat>
>
> Any thoughts?

@control on the setfocus element must be an IDREF, it's not actually
an Xpath expression. So what you have won't do anything at all.
I haven't tested this, but giving the textarea an ID should allow you
to focus it as part of the trigger's action. The plugin doesn't
currently handle repeated IDs quite properly (it doesn't make them
unique), but I think there's code in there that will pick the correct
repeated control for a given IDREF based off the current repeat index.
_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: getting focus on a repeated textarea after insert

dr.cw.ray
On Aug 10, 5:17 am, Dion <[hidden email]> wrote:

> On Aug 10, 5:20 am, "dr.cw.ray" <[hidden email]> wrote:
>
>
>
> > Hey all,
> > Just can't seem to get the right focus. I am adding a nodeset with
> > insert into a repeat. When  I click on the "add" label, I need the
> > focus to move down to the last textarea that was just added (instead
> > of just remaining on the "add" label). This is because I have a long
> > list and it is not convenient for the user to have to scroll or page
> > down a long list to get to the recently added post (textarea).  I'm
> > trying to use xforms-setfocus, but maybe that's the wrong approach--?
>
> > Here is my code snippet.
>
> > the xml instance structure is below; it is identical for the id="main"
> > instance and the id="inst2" instance ( "inst2" is just the dummy
> > instance I use for populating the "main" instance)
>
> >   <xf:instance id="inst2">
> >     <board xmlns="">
> >       <boardTitle/>
> >       <topic>
> >         <topicTitle>New</topicTitle>
> >         <post>
> >           <user>User</user>
> >           <date/>
> >           <content>content</content>
> >         </post>
> >       </topic>
> >     </board>
> >   </xf:instance>
>
> > Here is the insert action of my xforms-trigger with "add" label:
>
> >         <xf:action ev:event="DOMActivate">
>
> >             <xf:insert
> >                origin="instance('inst2')/topic/post"
> >                nodeset="post"
> >                at="post[position()=last()]"
> >                position="after" />
>
> >             <xf:setfocus control="position()=last()"/>
>
> >          </xf:action>
>
> > The "postition()=last()" was just the last thing I tried out of
> > several attempts. I also tried "repeatPost" and "post[position()=last
> > ()]" and "content[position()=last()]" and "last()" and "index" and
> > "index[last()]" and I can't remember what else. I love xforms but this
> > is the one area of using xforms that I just can't seem to "get".
>
> > Here is the actual repeat that is being inserted into.  Notice that
> > the xf:textarea references the node "content" which is where I need
> > the focus to go, so that the form moves down to the bottom of the list
> > automatically.
>
> >          <xf:repeat nodeset="post" id="repeatPost">
>
> >             <xf:label>User</xf:label>
> >             <xf:output ref="user">
> >             <xf:output  value="concat(substring(./date,
> > 6,2),'/',substring(./date,9,2),'/',
> >                 substring(./date,1,4),' - ', substring(./date,12,5))"/
>
> >             <xf:textarea ref="content">
> >                <xf:setvalue ev:event="xforms-value-changed" ref="../
> > @pEdited" value="1"/>
> >             </xf:textarea>
>
> >          </xf:repeat>
>
> > Any thoughts?
>
> @control on the setfocus element must be an IDREF, it's not actually
> an Xpath expression. So what you have won't do anything at all.
> I haven't tested this, but giving the textarea an ID should allow you
> to focus it as part of the trigger's action. The plugin doesn't
> currently handle repeated IDs quite properly (it doesn't make them
> unique), but I think there's code in there that will pick the correct
> repeated control for a given IDREF based off the current repeat index.

Adding an IDREF to anything inside the repeat doesn't work, e.g. in my
case the textarea that references the content node. I guess that makes
sense, since the ID in a repeat can't be unique then it can't be used
for gaining focus.
_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: getting focus on a repeated textarea after insert

dr.cw.ray
In reply to this post by Dion Sole
On Aug 10, 5:17 am, Dion <[hidden email]> wrote:

> On Aug 10, 5:20 am, "dr.cw.ray" <[hidden email]> wrote:
>
>
>
> > Hey all,
> > Just can't seem to get the right focus. I am adding a nodeset with
> > insert into a repeat. When  I click on the "add" label, I need the
> > focus to move down to the last textarea that was just added (instead
> > of just remaining on the "add" label). This is because I have a long
> > list and it is not convenient for the user to have to scroll or page
> > down a long list to get to the recently added post (textarea).  I'm
> > trying to use xforms-setfocus, but maybe that's the wrong approach--?
>
> > Here is my code snippet.
>
> > the xml instance structure is below; it is identical for the id="main"
> > instance and the id="inst2" instance ( "inst2" is just the dummy
> > instance I use for populating the "main" instance)
>
> >   <xf:instance id="inst2">
> >     <board xmlns="">
> >       <boardTitle/>
> >       <topic>
> >         <topicTitle>New</topicTitle>
> >         <post>
> >           <user>User</user>
> >           <date/>
> >           <content>content</content>
> >         </post>
> >       </topic>
> >     </board>
> >   </xf:instance>
>
> > Here is the insert action of my xforms-trigger with "add" label:
>
> >         <xf:action ev:event="DOMActivate">
>
> >             <xf:insert
> >                origin="instance('inst2')/topic/post"
> >                nodeset="post"
> >                at="post[position()=last()]"
> >                position="after" />
>
> >             <xf:setfocus control="position()=last()"/>
>
> >          </xf:action>
>
> > The "postition()=last()" was just the last thing I tried out of
> > several attempts. I also tried "repeatPost" and "post[position()=last
> > ()]" and "content[position()=last()]" and "last()" and "index" and
> > "index[last()]" and I can't remember what else. I love xforms but this
> > is the one area of using xforms that I just can't seem to "get".
>
> > Here is the actual repeat that is being inserted into.  Notice that
> > the xf:textarea references the node "content" which is where I need
> > the focus to go, so that the form moves down to the bottom of the list
> > automatically.
>
> >          <xf:repeat nodeset="post" id="repeatPost">
>
> >             <xf:label>User</xf:label>
> >             <xf:output ref="user">
> >             <xf:output  value="concat(substring(./date,
> > 6,2),'/',substring(./date,9,2),'/',
> >                 substring(./date,1,4),' - ', substring(./date,12,5))"/
>
> >             <xf:textarea ref="content">
> >                <xf:setvalue ev:event="xforms-value-changed" ref="../
> > @pEdited" value="1"/>
> >             </xf:textarea>
>
> >          </xf:repeat>
>
> > Any thoughts?
>
> @control on the setfocus element must be an IDREF, it's not actually
> an Xpath expression. So what you have won't do anything at all.
> I haven't tested this, but giving the textarea an ID should allow you
> to focus it as part of the trigger's action. The plugin doesn't
> currently handle repeated IDs quite properly (it doesn't make them
> unique), but I think there's code in there that will pick the correct
> repeated control for a given IDREF based off the current repeat index.

forgot to mention that my "add" trigger is sitting outside the
repeat.

I can try putting it inside the repeat so that rather than having a
single "add" button for the whole list, there will be one next to each
textarea, therefore, the focus will always be right next to where the
action took place.  However, last time I tried putting it into the
repeat I had a dandy of a time trying to get my xpath expressions
right--my weak area in xforms.
_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: getting focus on a repeated textarea after insert

Alessandro Vernet
In reply to this post by dr.cw.ray
dr.cw.ray wrote
Adding an IDREF to anything inside the repeat doesn't work, e.g. in my
case the textarea that references the content node. I guess that makes
sense, since the ID in a repeat can't be unique then it can't be used
for gaining focus.
Would you have a minimal stand-alone example that shows this unexpected behavior? If you could share this here, it would help us give you some better feedback on this.

Alex
Reply | Threaded
Open this post in threaded view
|

Re: getting focus on a repeated textarea after insert

dr.cw.ray
In reply to this post by dr.cw.ray
On Aug 14, 6:29 am, Alessandro Vernet <[hidden email]> wrote:

> dr.cw.ray wrote:
>
> > Adding an IDREF to anything inside the repeat doesn't work, e.g. in my
> > case the textarea that references the content node. I guess that makes
> > sense, since the ID in a repeat can't be unique then it can't be used
> > for gaining focus.
>
> Would you have a minimal stand-alone example that shows this unexpected
> behavior? If you could share this here, it would help us give you some
> better feedback on this.
>
> Alex
>
> -----
> Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
> Orbeon's Blog:http://www.orbeon.com/blog/
> Personal Blog:http://avernet.blogspot.com/
> Twitter -http://twitter.com/avernet
> --
> View this message in context:http://www.nabble.com/getting-focus-on-a-repeated-textarea-after-inse...
> Sent from the Mozilla - XForms mailing list archive at Nabble.com.

I think I can do that.I need to wrap up a few other things I'm on and
then I'll post a test case as soon as I can.
_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: getting focus on a repeated textarea after insert

dr.cw.ray
On Aug 15, 4:43 am, "dr.cw.ray" <[hidden email]> wrote:

> On Aug 14, 6:29 am, Alessandro Vernet <[hidden email]> wrote:
>
>
>
> > dr.cw.ray wrote:
>
> > > Adding an IDREF to anything inside the repeat doesn't work, e.g. in my
> > > case the textarea that references the content node. I guess that makes
> > > sense, since the ID in a repeat can't be unique then it can't be used
> > > for gaining focus.
>
> > Would you have a minimal stand-alone example that shows this unexpected
> > behavior? If you could share this here, it would help us give you some
> > better feedback on this.
>
> > Alex
>
> > -----
> > Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
> > Orbeon's Blog:http://www.orbeon.com/blog/
> > Personal Blog:http://avernet.blogspot.com/
> > Twitter -http://twitter.com/avernet
> > --
> > View this message in context:http://www.nabble.com/getting-focus-on-a-repeated-textarea-after-inse...
> > Sent from the Mozilla - XForms mailing list archive at Nabble.com.
>
> I think I can do that.I need to wrap up a few other things I'm on and
> then I'll post a test case as soon as I can.

Alex, here is the minimum text case you asked for, two actually, but I
believe it's a FF bug.  When inserting a node into a single repeat (in
my example, a list of posts represented by a textarea), you can just
add an IDREF to the post/textarea that is inside the repeat and it
works; it will send the focus to the newly added post/textare and jump
down to the hidden part of the bottom of the page.
see: http://ztags4xforms.com/testInsertAtEnd.xhtml

However, if you try the same thing in a nested repeat (in my example,
posts/textareas repeat inside a topics repeat)  you don't get the same
effect.
see: http://ztags4xforms.com/testInsertAtEnd2.xhtml

For now, all I can think is that my users will just have to scroll
down -- bugger.

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms