Search code examples
tapestry

Can check tapestry textfield via onValueChanged


Im working on a tapestry 5.4 project, where I should listen an input field (textfield) tapestry element changing. Is it possible to make an onValueChanged on textfield like on a select dom element (e.g.: http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/select1) ? I tried to made it on textfield, but did not work.

Or how do you solve this problem in tapestry? I thought about writing js module for that.. but that would be not a "tapestry way".

Thanks the answers in advance!


Solution

  • TextField does not fire a change event by default, as you've noticed. You could create a mixin however which is placed on an element and fires the event based on a certain client-side event. Possibly doing a zone-update at the end of the request.

    A good start would be this link which created a component which does exactly that. You pass in the client-side event on what you want to listen, which event you want to fire and what zone to update.

    This is a bit outdated however but you can indeed convert it to a js module, using JQuery instead of ProtoType. The ZoneManager is defined within the t5/core/zone module and you'll call deferredZoneUpdate(zoneId, evtEndpoint).

    The good part about this mixin is that it's "the Tapestry way" and re-usable for all components. For example, a zone update that should happen on a radio button change. Also doesn't work out-of-the-box. It does with this mixin.