public class Validator extends DataClass
Validators are
specified for DataSource fields via the validators
property. Validators that need not be run on the server can also be specified for a specific FormItem
or ListGridField
.
Smart
GWT supports a powerful library of ValidatorTypes
which have identical
behavior on both the client and the server.
Beyond this, custom validators can be defined on the client and
custom validation logic added on the server. Note that the regexp
and mask
validator types
are very flexible and can be used to perform virtually any kind of formatting check that doesn't involve some large
external dataset.
Custom validators can be reused on the client by adding them to the global validator list, via the
Validator.addValidator()
method.
ValidatorType
factoryCreated, factoryProperties
Constructor and Description |
---|
Validator() |
Validator(JavaScriptObject jsObj) |
Modifier and Type | Method and Description |
---|---|
static void |
addValidatorDefinition(java.lang.String name,
Validator validator)
Register a new standard validator type for reuse, by name.
|
static void |
create()
A Validator shouldn't be created directly.
|
java.lang.Boolean |
getClientOnly()
Indicates this validator runs on the client only.
|
java.lang.String[] |
getDependentFields()
User-defined list of fields on which this validator depends.
|
static Validator |
getOrCreateRef(JavaScriptObject jsObj) |
java.lang.Boolean |
getStopIfFalse()
Normally, all validators defined for a field will be run even if one of the validators has already failed.
|
java.lang.Boolean |
getStopOnError()
Indicates that if this validator is not passed, the user should not be allowed to exit the field - focus will be forced
back into the field until the error is corrected.
|
ValidatorType |
getType()
Type of the validator.
|
java.lang.String |
getTypeAsString()
Type of the validator.
|
java.lang.Boolean |
getValidateOnChange()
If true, validator will be validated when each item's "change" handler is fired as well as when the entire form is
submitted or validated.
|
void |
setClientOnly(java.lang.Boolean clientOnly)
Indicates this validator runs on the client only.
|
void |
setDependentFields(java.lang.String[] dependentFields)
User-defined list of fields on which this validator depends.
|
void |
setErrorMessage(java.lang.String errorMessage)
Text to display if the value does not pass this validation check.
|
void |
setStopIfFalse(java.lang.Boolean stopIfFalse)
Normally, all validators defined for a field will be run even if one of the validators has already failed.
|
void |
setStopOnError(java.lang.Boolean stopOnError)
Indicates that if this validator is not passed, the user should not be allowed to exit the field - focus will be forced
back into the field until the error is corrected.
|
void |
setType(java.lang.String type)
Type of the validator.
|
void |
setType(ValidatorType type)
Type of the validator.
|
void |
setValidateOnChange(java.lang.Boolean validateOnChange)
If true, validator will be validated when each item's "change" handler is fired as well as when the entire form is
submitted or validated.
|
applyFactoryProperties, doAddHandler, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsDoubleArray, getAttributeAsFloat, getAttributeAsInt, getAttributeAsIntArray, getAttributeAsJavaScriptObject, getAttributeAsLong, getAttributeAsMap, getAttributeAsObject, getAttributeAsRecord, getAttributeAsString, getAttributeAsStringArray, getAttributes, getHandlerCount, isFactoryCreated, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttributeAsJavaObject, setFactoryCreated
public Validator()
public Validator(JavaScriptObject jsObj)
public static Validator getOrCreateRef(JavaScriptObject jsObj)
public void setClientOnly(java.lang.Boolean clientOnly)
Normally, if the server is trying to run validators and finds a validator that it can't execute, for safety reasons validation is considered to have failed. Use this flag to explicitly mark a validator that only needs to run on the client.
clientOnly
- Default value is falsepublic java.lang.Boolean getClientOnly()
Normally, if the server is trying to run validators and finds a validator that it can't execute, for safety reasons validation is considered to have failed. Use this flag to explicitly mark a validator that only needs to run on the client.
public void setDependentFields(java.lang.String[] dependentFields)
applyWhen
criteria.
Note : This is an advanced setting
dependentFields
- Default value is nullcom.smartgwt.client.widgets.form.validator.Validator#setApplyWhen
public java.lang.String[] getDependentFields()
applyWhen
criteria.com.smartgwt.client.widgets.form.validator.Validator#getApplyWhen
public void setErrorMessage(java.lang.String errorMessage)
If unspecified, default error messages exist for all built-in validators, and a generic message will be used for a custom validator that is not passed.
errorMessage
- Default value is nullpublic void setStopIfFalse(java.lang.Boolean stopIfFalse)
stopIfFalse
is set, validation will not proceed beyond this validator if the check fails. This is useful to prevent expensive validators from being run unnecessarily, or to allow custom validators that don't need to be robust about handling every conceivable type of value.
stopIfFalse
- Default value is falsepublic java.lang.Boolean getStopIfFalse()
stopIfFalse
is set, validation will not proceed beyond this validator if the check fails. This is useful to prevent expensive validators from being run unnecessarily, or to allow custom validators that don't need to be robust about handling every conceivable type of value.
public void setStopOnError(java.lang.Boolean stopOnError)
This property defaults to stopOnError
if unset.
Enabling this property also
implies validateOnExit
is automatically
enabled. If this is a server-based validator, setting this property also implies that synchronousValidation
is forced on.
stopOnError
- Default value is nullpublic java.lang.Boolean getStopOnError()
This property defaults to stopOnError
if unset.
Enabling this property also
implies validateOnExit
is automatically
enabled. If this is a server-based validator, setting this property also implies that synchronousValidation
is forced on.
public void setType(ValidatorType type)
This can be one of the built-in ValidatorType
, the string
"custom" to define a custom validator, or the string "serverCustom" to define a server-only custom validator.
type
- Default value is nullpublic ValidatorType getType()
This can be one of the built-in ValidatorType
, the string
"custom" to define a custom validator, or the string "serverCustom" to define a server-only custom validator.
public void setType(java.lang.String type)
This can be one of the built-in ValidatorType
, the string
"custom" to define a custom validator, or the string "serverCustom" to define a server-only custom validator.
type
- Default value is nullpublic java.lang.String getTypeAsString()
This can be one of the built-in ValidatorType
, the string
"custom" to define a custom validator, or the string "serverCustom" to define a server-only custom validator.
public void setValidateOnChange(java.lang.Boolean validateOnChange)
Note that this property can also be set at the form/grid or field level; If true at any level and not explicitly false on the validator, the validator will be fired on change - displaying errors and rejecting the change on validation failure.
validateOnChange
- Default value is nullpublic java.lang.Boolean getValidateOnChange()
Note that this property can also be set at the form/grid or field level; If true at any level and not explicitly false on the validator, the validator will be fired on change - displaying errors and rejecting the change on validation failure.
public static void create()
validators
or wherever a Validator is needed.public static void addValidatorDefinition(java.lang.String name, Validator validator)
ValidatorType.CUSTOM
.
Any new validator where setType(String)
is set to the registered
name will pick up all properties (error message, condition, etc)
from this validator definition.
name
- name under which validator properties will be availablevalidator
- validator containing standard properties for reuse