useValidation()
WARNING
Single File Component (SFC) support for Administration extensions is experimental. It is available since Shopware 6.7.16.0. The APIs described on this page can still change without a deprecation. Try it out and tell us what you find, but do not ship an extension built on it to customers or to the Shopware Store until the API is declared stable (planned for 6.9).
import { useValidation } from 'shopware:composables';
function useValidation(options: { validation: () => ValidationRules }): {
validationService: ValidationService;
validate: (value: unknown) => boolean;
validateRule: (value: unknown, rule: string) => boolean;
};Runs a value against validation rules - a boolean, a rule name, a comma-separated list of names, or an array of either.
const { validate } = useValidation({ validation: () => props.validation });
const isValid = computed(() => validate(currentValue.value));The rules arrive as a getter so they stay reactive when the component's validation prop changes. The rules themselves come from the injected validationService.
No isValid
The mixin also exposed an isValid computed that read the host's current value under whichever of currentValue, value or selections happened to exist. A composable cannot guess that name, so it is not there - pass the value to validate() yourself, as above.
Replaces the validation mixin.