Hi all,

We've just finished migrating out app from tap 3 to tap 4 (well done to all involved, tap4 is great), and now we are starting to test out the Tacos Ajax components. (Tap 4.0.2 and Tacos 4.0.0)

We are running into some problems with integrating Ajax forms with client side validation. If we use tapestry standard validators (required, min, etc) then the tacos validation works as it does in the demo i.e. adds an error message next to the invalid field and clears the message when you add to it.

However, for one of our components we have defined a custom validator and translator. Our custom translator extends org.apache.tapestry.form.translator.NumberTranslator and also has Javascript component (which we build via renderContribution: we add a submit handler that calls a JS function that we define on our classpath).

The Ajax form (which contains our component with the customer translator) is first loaded into the page using an AjaxDirectLink. The problem is that when we do an ajax submit using the tacos components we get JS errors in the browser complaining about not being able to find our JS function (Tapestry.validate_currency, see below). Tacos then fails back to a

So the question is: what is the correct way for us to build custom validators and translators such that they work correctly with Tacos's client side validation? can someone point me to a tutorial or example where this is done?

Thanks
Richard

// our custom translator class

public class CurrencyTranslator extends NumberTranslator {
    @Override
    protected String defaultScript() {
        return "/js/CurrencyTranslator.js";
    }

    @Override
    protected Object parseText(
IFormComponent field, ValidationMessages messages, String text) throws ValidatorException {

        // snip: biz logic removed
    }

    @Override
public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { String message = TapestryUtils.enquote(buildMessage(context, field, getMessageKey()));

        // Set the script for this component
        context.includeClasspathScript(defaultScript());
context.addSubmitHandler("function(event) { Tapestry.validate_currency(event, '"
                    + field.getClientId() + "', " + message + "); }");
    }
}

// our custom JS function located in WEB-INF/js
Tapestry.validate_currency = function(event, fieldId, message)
  var field = this.find(fieldId);
  // snip: biz logic removed
}




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

Reply via email to