Search code examples
formsvalidationsmartgwt

add Validator to existing FormItem Validators in smartgwt


in a smartgwt DynamicForm, how can I add a validator to an existing set of validators within a FormItem ?

The only method I found in the official api is "setValidator(Validator)", but this seems to overwrite all the existing ones.

I would prefer a java approach to this (i.e. using smartgwt api), but in the end, if no solutions are available, at least a "js" native method would do the job.

thanks


Solution

  • Most likely, you don't want to by trying to dynamically add a validator at all.

    First, read the Data Binding section of the QuickStart Guide, which shows how you can add screen-specific validators to a form while still inheriting validators declared in the DataSource.

    Second, if you're trying to dynamically change the list of validators because some data that validation depends on is changing, take a look at the CustomValidator instead.

    If you have some reason to add a validator dynamically that isn't handled by these approaches, try explaining it in detail.

    Finally, you can continue with your current approach (not recommended) if you just refactor such that you can provide all the appropriate validators to the FormItems in a single setValidators() call.