]> git.localhorst.tv Git - alttp.git/blob - resources/js/schema/yup.js
save tracker config
[alttp.git] / resources / js / schema / yup.js
1 import * as yup from 'yup';
2
3 import { parseTime } from '../helpers/Result';
4
5 yup.addMethod(yup.string, 'time', function (errorMessage) {
6         return this.test('test-time-format', errorMessage, function (value) {
7                 const { path, createError } = this;
8                 return (
9                         !value ||
10                         !isNaN(parseTime(value)) ||
11                         createError({ path, message: errorMessage || 'validation.error.time' })
12                 );
13         });
14 });
15
16 yup.setLocale({
17         mixed: {
18                 default: 'validation.error.general',
19                 required: 'validation.error.required',
20         },
21         string: {
22                 time: 'validation.error.time',
23                 url: 'validation.error.url',
24         },
25 });
26
27 export default yup;