Nice post! and came at just the right time for me too... so thanks for the tips!

+1 for feature addition, any Jira open?

cheers,
Peter 
 
----- Original Message -----
From: "Juan Isern" <juanis...@gmail.com>
To: users@tapestry.apache.org
Sent: Friday, 9 April, 2010 08:09:40 GMT +02:00 Athens, Beirut, Bucharest, 
Istanbul
Subject: Re: Tweaking an AjaxFormLoop


Robert, following your recomendation finally implemented a component that
does basically nothing but register itself as a trigger and has an id
assigned by tap as well.

On the client side, I have a global map<triggerId, rowInjector> and a
function triggerRowInjector(triggerId) so that I can inject rows
selectively.

As for the effect thing, you can see that they're hardcoded in the function
Tapestry.Initializer.formLoopRemoveLink so I overrode it making them
consistent.

I'm using tapestry 5.1.0.5, so I expect this "solution" to be broken by...
5.2, maybe? :P




Robert Zeigler wrote:
> 
> That just sounds like you're asking for trouble down the road,  
> though. ;)
> You're effectively relying on implementation details of the component.  
> It'll break if:
>    * AjaxFormLoop changes the id of the contained RowInjector component
>    * You want more than one AjaxFormLoop on the page
> 
> I'll grant you that it works... for now. :) And it's the sort of  
> solution I might put in projects that I write for myself, but not a  
> solution I would put into a project I write for clients.
> 
> It's probably worth submitting a jira for a feature addition to make  
> this sort of functionality easier/more robust.
> 
> Robert
> 
> On Apr 8, 2010, at 4/89:20 PM , Brian Heston wrote:
> 
>> I've done something similar without much hacking.  In my case I have  
>> an autocomplete field in each row, and when a selection is made I  
>> needed to add a new row automatically so the user can enter the next  
>> item.  I found that the row injector always has the same name, so I  
>> just call the trigger function defined in tapestry.js when I want to  
>> add the new row.  The addRow parameter is empty so the link doesn't  
>> render, but the trigger still does.
>>
>> <div t:type="ajaxFormLoop" t:source="items" t:value="item">
>>    <t:submitNotifier>
>>        <input type="text" t:type="textField" t:value="item.name"  
>> t:mixins="autocomplete2" t:afterUpdateElement="itemSelected"/>
>>    </t:submitNotifier>
>>    ...
>>    <t:parameter name="addRow"></t:parameter>
>> </div>
>>
>> function itemSelected() {
>>    $("rowInjector").trigger();
>> }
>>
>> You may notice that I'm using my own autocomplete mixin, which I had  
>> to make to expose the afterUpdateElement event, but if you've got  
>> some other logic that invokes the adding of a row the idea should be  
>> the same.
>>
>> Hope this helps,
>> Brian
>>
>>
>> ________________________________________
>> From: Juan Isern [juanis...@gmail.com]
>> Sent: Thursday, April 08, 2010 6:43 PM
>> To: users@tapestry.apache.org
>> Subject: Re: Tweaking an AjaxFormLoop
>>
>> Robert, I've got to say that you gave me the answer that I feared  
>> most.
>>
>> Hehe, REALLY thanks for your tips, I knew already that sooner or  
>> later I had
>> to hack into tapestry.js
>>
>> Cheers!
>>
>>
>> Robert Zeigler wrote:
>>>
>>>
>>> On Apr 8, 2010, at 4/81:48 PM , Juan Isern wrote:
>>>
>>>> What I would like to do is to trigger an "addRow" event by executing
>>>> some
>>>> javascript (that will be invoked when an upload finishes). I thought
>>>> of
>>>> simulating a click event on an invisible "add row" link but I'm sure
>>>> there's
>>>> a prettier solution out there.
>>>>
>>>
>>> There are other ways to do it, although I'm not sure I would call  
>>> them
>>> "prettier". :)
>>> AjaxFormLoop places an "AjaxFormLoopContext" object into the
>>> environment when it renders.
>>> You can access this object and add a call to "addAddRowTrigger".   
>>> That
>>> part is pretty. The main issue (for you) is that tapestry then  
>>> assumes
>>> that the trigger is going to be invoked on the "click" action, which
>>> isn't what you want in this case.
>>> There's a way around it, and that's where things get uglier. You can
>>> monkey patch tapestry.js to override
>>> Tapestry.Initializer.ajaxFormLoop, and make it behave how you want.
>>> This is typically how I've implemented custom "add row"  
>>> functionality.
>>>
>>> It might be a nifty change to enable a second form of the
>>> "addAddRowTrigger" that takes, say, a js callback name as a 2nd
>>> argument.  Or perhaps some flag triggering whether the first argument
>>> is an id or a callback.  In any event, the initializer could then
>>> check for the appropriate condition, and if the condition is met, the
>>> initializer would delegate the setup to the callback, passing in the
>>> row injector, rather than assuming a click.  If there's enough
>>> interest in something like this, I would be willing to do the work to
>>> add it to the framework (the exact api would need to be worked out,
>>> though).
>>>
>>>
>>>> The same question could apply to any client-side ajax behavior, like
>>>> refreshing zones. Is there any way to do it programmatically via
>>>> javascript?
>>>>
>>>
>>> The best answer here is to take a look for yourself through (mainly)
>>> the tapestry.js file.
>>> But, yes, you can refresh zones in non-default ways; the trick (as
>>> with AjaxFormLoop above) is getting a handle to the runtime js  
>>> objects.
>>>
>>>> Another thing: the javascript effect displayed when a row is added/
>>>> removed
>>>> behaves in a somewhat weird fashion. Can be this effect be  
>>>> disabled or
>>>> configured?
>>>>
>>>
>>> http://tapestry.apache.org/tapestry5.1/tapestry-core/ref/org/apache/tapestry5/corelib/components/AjaxFormLoop.html
>>> Check out the "show" parameter.
>>>
>>>> Thanks a lot!
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Tweaking-an-AjaxFormLoop-tp28182870p28182870.html
>>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Tweaking-an-AjaxFormLoop-tp28182870p28186610.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Tweaking-an-AjaxFormLoop-tp28182870p28187698.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to