Skip to main content

hasSelections()

const hasSelections: (value, fieldName) => string;

Validates array has at least one selection and no duplicates

Parameters

ParameterTypeDescription
valuestring[]The array to validate
fieldNamestringThe name of the field for error messages

Returns

string

Empty string if valid, error message if invalid

Example

hasSelections([], "expertise") // Returns: "Please select at least one expertise."
hasSelections(["Python"], "expertise") // Returns: ""
hasSelections(["Python", "Python"], "expertise") // Returns: "Please remove duplicate expertise selections."
hasSelections(null, "expertise") // Returns: "Please select at least one expertise."