System Information
- Strapi Version: 3.6.9
- Operating System: Windows 10
- Database: MySQL
- Node Version: 14.20.0
- NPM Version: 6.14.17
- Yarn Version: 1.22.19
strapi.errors.badRequest('Price must be between 1.000.000 and 150.000.000');
It’s been a while since the question is asked but still it might help someone else.
First requirement here is that your backend should allow to save the value without constrains.
On the frontend side you can do your validation before saving, and then use showNotification() hook from strapi to send a warning message as a parallel process in your saveHandler.
import { useNotification } from "@strapi/helper-plugin";
...
const YourAwesomeComponent = () => {
const showNotification = useNotification();
const save = () => {
if (price > 150000000 || price <1000000 ) {
// This shows a notification message as a warning
// @see https://github.com/strapi/strapi/blob/v4.21.1/packages/core/helper-plugin/src/features/Notifications.tsx#L26
// If you are using newer version of strapi then check the new version of this file, it may be changed over time
showNotification({ message: "Price must be between 1.000.000 and 150.000.000", title: "Success", type: 'softWarning'});
}
// proceed to save logic
}
// ...
}
The same way you can use to display success message as well, just by changing the type
of showNotification