You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jayson Pierringer <ja...@gemex.com> on 2008/12/18 23:03:21 UTC

T5 I am struggling with persisting form elements using onchange

I have three Select components and a TextField component on my form 
(customerSelect, locationSelect, deviceSelect, problemTextField).  What 
is supposed to happen is when the user selects a customer the 
locationSelect component should be filled with the locations associated 
with the selected customer.  I attempted this using the onEvent mixin 
and a javascript function, but Tapestry kept telling me my javascript 
function was undefined.

I decided to simplify and eliminate the OnEvent mixin and use onchange 
instead.  The problem is onchange doesn't seem to allow Tapestry to 
persist any of the form fields.

Now I am using a combination of both OnEvent and onchange.  Using this 
approach the customerSelect component persists I think because of the 
OnEvent mixin, but the other components reset every time a new customer 
is selected.
Here is the customerSelect definition from my tml file.
<select t:type="select" t:id="customerSelect" 
t:model="selectModelCustomers" t:encoder="selectModelCustomers" 
t:value="selectedCustomer" t:mixins="commons/OnEvent" event="change" 
onchange="document.forms[0].submit()">

I am hoping someone can point me in the right direction if there is a 
more conventional way of updating a form based on a user's actions.  
Otherwise maybe help me find the reason my current approach isn't 
working.  I can include more code if that will help to better understand 
what I am requesting.

The only other thing is if I initialize the customerSelect in onActivate 
the select is always one selection behind (ie. I choose a customer and 
when the page refreshes the select component is not updated, I then 
choose a different customer and the select is updated with my first 
selection... ) -- probably because of my use of onchange.  So instead I 
am initializing it in the java page's constructor and that fixed the 
delay problem.  If anyone has any insight regarding this I would love to 
hear it.

I would love for this to work with AJAX using the OnEvent mixin and an 
onCompleteCallback javascript event, but it doesn't have to.  Submitting 
the entire form to update the necessary components is acceptable for 
this project.

Thank you,

Jayson Pierringer


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


Re: T5 I am struggling with persisting form elements using onchange

Posted by Lutz Hühnken <lh...@googlemail.com>.
Jayson,

> customer.  I attempted this using the onEvent mixin and a javascript
> function, but Tapestry kept telling me my javascript function was undefined.

that's probably just some mismatch between your  function name and
what you said the callback function was. Maybe you should post that
code here.

> I decided to simplify and eliminate the OnEvent mixin and use onchange
> instead.  The problem is onchange doesn't seem to allow Tapestry to persist
> any of the form fields.

Hm... what did you do onchange? That's all a bit confusing... if you
use onEvent with event=change, of course you also use the "onchange"
event. The change event will cause an ajax call that will cause some
code on the server to be executed, and may return a result, which may
be passed to a "callback" JavaScript function.

> Now I am using a combination of both OnEvent and onchange.  Using this
> approach the customerSelect component persists I think because of the
[..]
> t:mixins="commons/OnEvent" event="change"
> onchange="document.forms[0].submit()">

What you are saying is, you have the onchange event trigger two
actions. That might get messy, how can you define which one is
triggered first? Plus, when you submit the form anyway, why the ajax
call?

> I am hoping someone can point me in the right direction if there is a more
> conventional way of updating a form based on a user's actions.  Otherwise

I think you should go back to using the OnEvent mixin, without
additional onchange calls such as a form submit. Have your event
handler update your data on the server side, have it return some value
that allows you to update your other select, and write a JavaScript
function that does the update.

> The only other thing is if I initialize the customerSelect in onActivate the
> select is always one selection behind (ie. I choose a customer and when the
> page refreshes the select component is not updated, I then choose a
> different customer and the select is updated with my first selection... )

That sounds odd. Maybe the onActivate you expect to be called is not
called at the time you expect it. You should trace/debug the
invocations.


> I would love for this to work with AJAX using the OnEvent mixin and an
> onCompleteCallback javascript event,

Should not be a problem.

Hth,

Lutz


--
http://www.altocon.de/
Software Development, Consulting
Hamburg, Germany

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