Class: FDataValidationBuilder
Builder for data validation rules. use FUniver univerAPI.newDataValidation()
to create a new builder.
Example
// Set the data validation for cell A1 to require a value from B1:B10
const range = FRange.create('Sheet1', 'B1:B10');
const rule = univerAPI.newDataValidation().requireValueInRange(range).build();
cell.setDataValidation(rule);
Methods
build()
build(): FDataValidation
Builds an FDataValidation instance based on the _rule property of the current class
Returns
A new instance of the FDataValidation class
Example
const builder = univerAPI.newDataValidation();
const validation = builder.requireNumberBetween(1, 10).build();
copy()
copy(): FDataValidationBuilder
Creates a duplicate of the current DataValidationBuilder object
Returns
A new instance of the DataValidationBuilder class
Example
const builder = univerAPI.newDataValidation();
const copy = builder.requireNumberBetween(1, 10).copy();
getAllowInvalid()
getAllowInvalid(): boolean
Determines whether invalid data is allowed
Returns
boolean
True if invalid data is allowed, False otherwise
Example
const builder = univerAPI.newDataValidation();
const allowsInvalid = builder.getAllowInvalid();
getCriteriaType()
getCriteriaType(): any
Gets the data validation type of the rule
Returns
any
The data validation type
Example
const builder = univerAPI.newDataValidation();
const type = builder.getCriteriaType();
getCriteriaValues()
getCriteriaValues(): [string, string, string]
Gets the values used for criteria evaluation
Returns
[string
, string
, string
]
An array containing the operator, formula1, and formula2 values
Example
const builder = univerAPI.newDataValidation();
const [operator, formula1, formula2] = builder.getCriteriaValues();
getHelpText()
getHelpText(): string
Gets the help text information, which is used to provide users with guidance and support
Returns
string
Returns the help text information. If there is no error message, it returns an undefined value
Example
const builder = univerAPI.newDataValidation();
const helpText = builder.getHelpText();
requireCheckbox()
requireCheckbox(checkedValue?, uncheckedValue?): FDataValidationBuilder
Sets the data validation type to CHECKBOX and sets the checked and unchecked values
Parameters
Parameter | Type | Description |
---|---|---|
checkedValue ? | string | The value when the checkbox is checked |
uncheckedValue ? | string | The value when the checkbox is unchecked |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireCheckbox('Yes', 'No').build();
requireDateAfter()
requireDateAfter(date): FDataValidationBuilder
Set the data validation type to DATE and configure the validation rules to be after a specific date
Parameters
Parameter | Type | Description |
---|---|---|
date | Date | The date to compare against |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireDateAfter(new Date('2024-01-01')).build();
requireDateBefore()
requireDateBefore(date): FDataValidationBuilder
Set the data validation type to DATE and configure the validation rules to be before a specific date
Parameters
Parameter | Type | Description |
---|---|---|
date | Date | The date to compare against |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireDateBefore(new Date('2024-12-31')).build();
requireDateBetween()
requireDateBetween(start, end): FDataValidationBuilder
Set the data validation type to DATE and configure the validation rules to be within a specific date range
Parameters
Parameter | Type | Description |
---|---|---|
start | Date | The starting date of the range |
end | Date | The ending date of the range |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder
.requireDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
.build();
requireDateEqualTo()
requireDateEqualTo(date): FDataValidationBuilder
Set the data validation type to DATE and configure the validation rules to be equal to a specific date
Parameters
Parameter | Type | Description |
---|---|---|
date | Date | The date to compare against |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireDateEqualTo(new Date('2024-01-01')).build();
requireDateNotBetween()
requireDateNotBetween(start, end): FDataValidationBuilder
Set the data validation type to DATE and configure the validation rules to be not within a specific date range
Parameters
Parameter | Type | Description |
---|---|---|
start | Date | The starting date of the date range |
end | Date | The ending date of the date range |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder
.requireDateNotBetween(new Date('2024-01-01'), new Date('2024-12-31'))
.build();
requireDateOnOrAfter()
requireDateOnOrAfter(date): FDataValidationBuilder
Set the data validation type to DATE and configure the validation rules to be on or after a specific date
Parameters
Parameter | Type | Description |
---|---|---|
date | Date | The date to compare against |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireDateOnOrAfter(new Date('2024-01-01')).build();
requireDateOnOrBefore()
requireDateOnOrBefore(date): FDataValidationBuilder
Set the data validation type to DATE and configure the validation rules to be on or before a specific date
Parameters
Parameter | Type | Description |
---|---|---|
date | Date | The date to compare against |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireDateOnOrBefore(new Date('2024-12-31')).build();
requireFormulaSatisfied()
requireFormulaSatisfied(formula): FDataValidationBuilder
Requires that a custom formula be satisfied
Parameters
Parameter | Type | Description |
---|---|---|
formula | string | The formula string that needs to be satisfied |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireFormulaSatisfied('=A1>0').build();
requireNumberBetween()
requireNumberBetween(
start,
end,
isInteger?): FDataValidationBuilder
Requires the user to enter a number within a specific range, which can be integer or decimal
Parameters
Parameter | Type | Description |
---|---|---|
start | number | The starting value of the number range |
end | number | The ending value of the number range |
isInteger ? | boolean | Indicates whether the required number is an integer |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireNumberBetween(1, 10).build();
requireNumberEqualTo()
requireNumberEqualTo(num, isInteger?): FDataValidationBuilder
Requires the user to enter a number that is equal to a specific value, which can be an integer or a decimal
Parameters
Parameter | Type | Description |
---|---|---|
num | number | The number to which the entered number should be equal |
isInteger ? | boolean | Indicates whether the required number is an integer |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireNumberEqualTo(10).build();
requireNumberGreaterThan()
requireNumberGreaterThan(num, isInteger?): FDataValidationBuilder
Requires the user to enter a number that is greater than a specific value, which can be an integer or a decimal
Parameters
Parameter | Type | Description |
---|---|---|
num | number | The number to which the entered number should be greater |
isInteger ? | boolean | Indicates whether the required number is an integer |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireNumberGreaterThan(10).build();
requireNumberGreaterThanOrEqualTo()
requireNumberGreaterThanOrEqualTo(num, isInteger?): FDataValidationBuilder
Requires the user to enter a number that is greater than or equal to a specific value, which can be an integer or a decimal
Parameters
Parameter | Type | Description |
---|---|---|
num | number | The number to which the entered number should be greater than or equal |
isInteger ? | boolean | Indicates whether the required number is an integer |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireNumberGreaterThanOrEqualTo(10).build();
requireNumberLessThan()
requireNumberLessThan(num, isInteger?): FDataValidationBuilder
Requires the user to enter a number that is less than a specific value, which can be an integer or a decimal
Parameters
Parameter | Type | Description |
---|---|---|
num | number | The number to which the entered number should be less |
isInteger ? | boolean | Indicates whether the required number is an integer |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireNumberLessThan(10).build();
requireNumberLessThanOrEqualTo()
requireNumberLessThanOrEqualTo(num, isInteger?): FDataValidationBuilder
Sets the data validation rule to require a number less than or equal to a specified value The specified value can be an integer or a decimal
Parameters
Parameter | Type | Description |
---|---|---|
num | number | The number to which the entered number should be less than or equal |
isInteger ? | boolean | Indicates whether the required number is an integer |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireNumberLessThanOrEqualTo(10).build();
requireNumberNotBetween()
requireNumberNotBetween(
start,
end,
isInteger?): FDataValidationBuilder
Sets a data validation rule that requires the user to enter a number outside a specified range The specified range includes all integers and decimals
Parameters
Parameter | Type | Description |
---|---|---|
start | number | The starting point of the specified range |
end | number | The end point of the specified range |
isInteger ? | boolean | Optional parameter, indicating whether the number to be verified is an integer |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireNumberNotBetween(1, 10).build();
requireNumberNotEqualTo()
requireNumberNotEqualTo(num, isInteger?): FDataValidationBuilder
Creates a data validation rule that requires the user to enter a number that is not equal to a specific value The specific value can be an integer or a decimal
Parameters
Parameter | Type | Description |
---|---|---|
num | number | The number to which the entered number should not be equal |
isInteger ? | boolean | Indicates whether the required number is an integer |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireNumberNotEqualTo(10).build();
requireValueInList()
requireValueInList(
values,
multiple?,
showDropdown?): FDataValidationBuilder
Sets a data validation rule that requires the user to enter a value from a list of specific values The list can be displayed in a dropdown, and the user can choose multiple values according to the settings
Parameters
Parameter | Type | Description |
---|---|---|
values | string [] | An array containing the specific values that the user can enter |
multiple ? | boolean | Optional parameter indicating whether the user can select multiple values |
showDropdown ? | boolean | Optional parameter indicating whether to display the list in a dropdown |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.requireValueInList(['Yes', 'No']).build();
requireValueInRange()
requireValueInRange(
range,
multiple?,
showDropdown?): FDataValidationBuilder
Sets a data validation rule that requires the user to enter a value within a specific range The range is defined by an FRange object, which contains the unit ID, sheet name, and cell range
Parameters
Parameter | Type | Description |
---|---|---|
range | FRange | An FRange object representing the range of values that the user can enter |
multiple ? | boolean | Optional parameter indicating whether the user can select multiple values |
showDropdown ? | boolean | Optional parameter indicating whether to display the list in a dropdown |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const range = FRange.create('Sheet1', 'B1:B10');
const rule = builder.requireValueInRange(range).build();
setAllowBlank()
setAllowBlank(allowBlank): FDataValidationBuilder
Sets whether to allow blank values
Parameters
Parameter | Type | Description |
---|---|---|
allowBlank | boolean | Whether to allow blank values |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.setAllowBlank(true).build();
setAllowInvalid()
setAllowInvalid(allowInvalidData): FDataValidationBuilder
Sets whether to allow invalid data and configures the error style If invalid data is not allowed, the error style will be set to STOP, indicating that data entry must stop upon encountering an error If invalid data is allowed, the error style will be set to WARNING, indicating that a warning will be displayed when invalid data is entered, but data entry can continue
Parameters
Parameter | Type | Description |
---|---|---|
allowInvalidData | boolean | Whether to allow invalid data |
Returns
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.setAllowInvalid(true).build();
setOptions()
setOptions(options): this
Sets the options for the data validation rule
Parameters
Parameter | Type | Description |
---|---|---|
options | IDataValidationRuleOptions | The options to set for the data validation rule |
Returns
this
The current instance for method chaining
Example
const builder = univerAPI.newDataValidation();
const rule = builder.setOptions({
allowBlank: true,
showErrorMessage: true,
error: 'Please enter a valid value'
}).build();