Steve,

If you prefer not to take the easy option and add a couple of radio buttons
to let the user select currency or percentage input, that could also control
a couple of labels (or a border) that shows, in a locale specific way, the
currency symbol or the percentage sign you could ... create an
AbsoluteOrPercentage class an instance of which will back the model of your
DiscountAmount field. Make a validator that checks that the last character
entered looks like an int or a '%' and that the other characters represent a
number, and, if required, put your validation messages in the appropriate
place. Add this validator to your DiscountAmount text field. Make an
appropriate converter (implement IConverter - very simple logic required for
both methods) and override getConverter on your text field to return it for
your AbsoluteOrPercentage class. If this text field will be useful
elsewhere, make a (top level) subclass of TextField -
AbsoluteOrPercentageTextField for instance that does all of the above.

It is not clear from your post what you want updated, but let's assume you
have three fields, one for each of SalePrice, DiscountAmount and
ActualAmount (price with discount applied) and you want the latter updated.
Add an AjaxFormComponentUpdatingBehavior (probably "onblur") to both the
input fields. In the onUpdate methods of each update the (dynamic) model
object backing the ActualAmount field (probably rendered by a label since it
is not meant to be edited by the user). Don't forget to add your
"actualAmountTextField" component to the AjaxRequestTarget in both your
onUpdate methods and also to request a markup id for actualAmountTextField -
actualAmountField.setMarkupId(true) - where you build up the container. If
this lot is likely to be useful elsewhere, wrap all three fields (and
probably all the rest of the stuff described above) in a Panel so you can
just drop it in a div anywhere you like later on.

Does that do it?

Regards - Cemal
http://www.jWeekend.co.uk  http://jWeekend.co.uk  




steve222 wrote:
> 
> Hi.  Hopefully I can explain this scenario OK - I'll try to keep it
> simple.
> 
> On a form, I have a couple of TextFields - SalePrice and DiscountAmount.  
> 
> After the user enters SalePrice, I need a way to allow the user to enter
> the DiscountAmount as either a flat rate or as a percentage of the
> SalePrice.
> 
> For example, if entered SalePrice is 1000, the user could enter a flat
> DiscountAmount of 200.00.  Or they could enter 20%.  I'd like the option
> to do either since SalePrice might be 8,745 and the discount 2.75% or
> something (so hard to just calculat the true cash amount).  Or it might
> just really be a flat £200 in which case hard to calculate the %.
> 
> In a traditional app where I'm writing the JavaScript, I can think of
> various ways to do this involving extra fields for flatrate and/or % -
> then updating the real DiscountAmount field when the "dummy" fields
> change.
> 
> But I'm trying to work out an elegant way with Wicket/AJAX - without too
> much success so far.  
> 
> Any suggestions - or links to similar examples?  Ideally, the fewer extra
> dummy fields the better.
> 
> Thanks. 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Wicket-AJAX-update-form-TextField-value-from-another-field-tp20117258p20120021.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to