Quantcast

Event on autocomplete in inserted item

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Event on autocomplete in inserted item

Heinrich Götzger
Hoi,

an existing item is copied on user-button-event into the list of items
as further line. The items will be rendered by using the legacy
fr-datatable which is hidden in an onw xbl-component. One item is one
line in the table.

How can I then manage to send a fr-set-label-event to an autocomplete
component of an element within the copied item. I always get the event
on the line I copied from, not on the copied item.

Looks like the 'focus' is sticky on the original item.

I tried without success to iterate with an dispatched event of the
copy-button over the complete list of items like:

<xf:action ev:event="copyContentLine"
       xxf:iterate="instance('content')/Items/item"
       if="normalize-space(TXT) != ''">

          <!-- get label from rest-service -->
          <xf:send
             submission="get-TXTItem-submission">
             <xf:property
                name="txt"
                value="normalize-space(TXT)"/>
          </xf:send>

          <xf:dispatch
             targetid="Item_TXT"
             name="fr-set-label">
             <!-- write label from rest-server into field -->
             <xf:property
                name="label"
                value="instance('submission')/txt/item/label"/>
          </xf:dispatch>

</xf:action>


The main-problem is the the label in the autocomplete component is not
shown where at the value is correct in the copied item-element.


Is this problem understandable?

Thanks for some help.


Cheers


Heinrich

--
Before printing this e-mail, think about our environmental responsibility.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Event on autocomplete in inserted item

Alessandro  Vernet
Administrator
Hi Heinrich,

In general, the `xxf:repeat-indexes` attribute on `xf:dispatch` allows you to target a specific "instance" of a control in a repeat. You can find more about this in the section linked below, however I am not sure this will work in the context of the fr:datatable. You'll let us know if this helps.

https://doc.orbeon.com/xforms/events-extensions-other.html#targeting-effective-controls-within-repeat-iterations

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Event on autocomplete in inserted item

Heinrich Götzger
Hoi Alex,

thanks for the quick response and the promising hint in the docs, I didn't know about that yet.

Dropping the iterate of my first tests and handle the event in the added line
following this advice is basically working.

My dispatch looks like:

         <xf:dispatch
            xxf:repeat-indexes="{position() + 1}"
            targetid="Item_TXT"
            name="fr-set-label">
            <!-- write label from rest-server into field -->
            <xf:property
               name="label"
               value="instance('submission')/txt/item/label"/>
         </xf:dispatch>

Interesting now is, that the actual insert needs more time than calling the submission and fire the
fr-set-label-event to update the TXT-control. So the result is that the control on the 'over-next-item' get's the update, not the next-line which got copied.

Tests with
         <xf:dispatch
            delay="10"

had no effect.


I'm a bit clueless.

Cheers

Heinrich

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Event on autocomplete in inserted item

Heinrich Götzger
Hoi Alex,

alternate implementation would be as following:

   <xf:action
      ev:observer="content"
      ev:event="xforms-insert">

      <xf:action
         xxf:iterate="instance('content')/Items/item"
         if="TXT != ''">

         <!-- get label from rest-service -->
         <xf:send submission="get-TXTItem-submission">
            <xf:property
               name="txt"
               value="TXT"/>
         </xf:send>

         <xf:dispatch
            xxf:repeat-indexes="{position()}"
            targetid="Item_TXT"
            name="fr-set-label">
            <!-- write label from rest-server into field -->
            <xf:property
               name="label"
               value="instance('submission')/txt/item/label"/>
         </xf:dispatch>

         <!-- delete tmp-node -->
         <xf:delete
            ev:event="xforms-insert"
            nodeset="instance('submission')/txt/item"/>

      </xf:action>
   </xf:action>

This is working as expected. The disadvantage of this solution is that I call the submission for every non-emtpy element every time a line is added, independently if it is copied or just added a empty new line.

Thanks and Cheers

Heinrich

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Event on autocomplete in inserted item

Alessandro  Vernet
Administrator
Hi Heinrich,

And you're saying that you'd like this to run only for inserted nodes, instead of all the nodes, for performance reasons? Then instead of iterating on `instance('content')/Items/item`, you could maybe use event('inserted-nodes') [1] to access just the nodes that were inserted?

Alex

[1] https://www.w3.org/community/xformsusers/wiki/XForms_2.0#The_xforms-insert_Event
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Event on autocomplete in inserted item

Heinrich Götzger
Hoi Alex,

yes, for performance reasons I'd like to avoid REST-requests for already
known labels.

Following your suggestion to work on inserted nodes is not working for
some reason. I can get the TXT and call the submission, but then I'm not
sure how to trigger the fr-set-label event to hit the correct
autocomplete control.

Thanks a lot for your support so far.

Heinrich

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Event on autocomplete in inserted item

Alessandro  Vernet
Administrator
Hi Heinrich,

I was just thinking that in your above code, in the <xf:action xxf:iterate="instance('content')/Items/item" if="TXT != ''">, instead iterating over:

    instance('content')/Items/item

You could iterate over:

    event('inserted-nodes')

Could that make sense?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Event on autocomplete in inserted item

Heinrich Götzger
Hoi Alex,

I tried this, submission is on inserted node(s) only :)

   <xf:action
      ev:observer="content"
      ev:event="xforms-insert"
      xxf:iterate="event('inserted-nodes')">

      <xf:action if="TXT != ''">

         <xf:send submission="get-TXTItem-submission">
            <xf:property
               name="txt"
               value="TXT"/>
         </xf:send>

         <xf:dispatch
            xxf:repeat-indexes="{position()}"
            targetid="Item_TXT"
            name="fr-set-label">
            <!-- write label from rest-server into field -->
            <xf:property
               name="label"
               value="instance('submission')/txt/item/label"/>
         </xf:dispatch>

      </xf:action>

   </xf:action>

But where to send the event to? the dispatch is always targeting first item in:

    instance('content')


What am I missing?

The xforms-insert event is not providing a concrete location information as number about the inserted node as the xforms-delete event does, for example, following the documentation under [1] ff. I could imagine something like: event('insert-location').


Thanks and cheers

Heinrich

[1] https://www.w3.org/community/xformsusers/wiki/XForms_2.0#The_xforms-insert_Event

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Event on autocomplete in inserted item

Alessandro  Vernet
Administrator
Hi Heinrich,

You're right: event('inserted-nodes') gives you nodes in the instance, but you want a position. You might be able to find the position from the node using something like count(preceding-sibling::*).

Alternatively, you might be able to use xxforms-nodeset-changed, which is dispatched to the xf:repeat, and will give you the position of the newly inserted iterations (see link below).

This is most useful when you have more complicated ref expression on the repeat, or some of the nodes are non-relevant; otherwise figuring the position with something along the lines of count(preceding-sibling::*) is maybe more straightforward.

https://doc.orbeon.com/xforms/events-extensions-events.html#repeat-control-events

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Loading...