com.smartgwt.client.widgets.form.validator.CustomValidator has 2 design problems : lack of registration facility and lack of access to the validator attributes from the data source field. The first problem is addressed in another thread (http://forums.smartclient.com/showthread.php?t=13923) and is fixed in nightly builds by adding a static method Validator.addValidatorDefinition(). The second problem though is still pending. There seem to be 2 possible paths to fixing as follows:
One solution could be to provide published API on DataSourceField (accessible through CustomValidator.dataSourceField) for retrieval of validator definitions bound to the field. This however would be cumbersome to use in custom validators because of the need to search for the correct definition and the problems in case that there are multiple validator definitions of the same type on the field.
Another solution could be to expose to Java code in CustomValidator one more field which points directly to the validator definition appropriate for the specific invocation of condition() and is available in the JavaScript call under the name "validator". This can be done e.g. through a Java field "protected DataClass dataSourceValidator". This field will be further managed in setup() and reset() in a fashion similar to the other already existing fields. Specifically initialization would be :
and clean up in reset would obviously be "dataSourceField = null".
It is probably clear from the above that I suggest adoption of the second solution and would be glad if Isomorphic adopts it.
One solution could be to provide published API on DataSourceField (accessible through CustomValidator.dataSourceField) for retrieval of validator definitions bound to the field. This however would be cumbersome to use in custom validators because of the need to search for the correct definition and the problems in case that there are multiple validator definitions of the same type on the field.
Another solution could be to expose to Java code in CustomValidator one more field which points directly to the validator definition appropriate for the specific invocation of condition() and is available in the JavaScript call under the name "validator". This can be done e.g. through a Java field "protected DataClass dataSourceValidator". This field will be further managed in setup() and reset() in a fashion similar to the other already existing fields. Specifically initialization would be :
Code:
if(validator !=null) { self.@com.smartgwt.client.widgets.form.validator.Custom Validator::dataSourceValidator = @com.smartgwt.client.core.DataClass::new(Lcom/google/gwt/core/client/JavaScriptObject;)(validator); } else { self.@com.smartgwt.client.widgets.form.validator.Custom Validator:dataSourceValidator = @com.smartgwt.client.core.DataClass::new()(); }
It is probably clear from the above that I suggest adoption of the second solution and would be glad if Isomorphic adopts it.
Comment