Skip to content

Instantly share code, notes, and snippets.

@ShunYamauchi
Created November 18, 2021 12:43

Revisions

  1. ShunYamauchi created this gist Nov 18, 2021.
    29 changes: 29 additions & 0 deletions useTest.tsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    const validateLunchBoxStyle = function (this: any) {
    const {
    lunchStyles,
    soups,
    salads
    } = this.parent
    return !(
    lunchStyles.includes('lunchBox') &&
    soups.length === 0 &&
    salads.length === 0
    )
    }

    object().shape(
    {
    lunchStyles: array().min(1, 'お昼ごはんの選択は必須です。'),
    salads: array().test(
    'salads_validation',
    'お弁当の場合は、スープまたはサラダの入力が必須です。',
    validateLunchBoxStyle
    ),
    soups: array().test(
    'soups_validation',
    'お弁当の場合は、スープまたはサラダの入力が必須です。',
    validateLunchBoxStyle
    )
    },
    [['salads', 'soups']]
    )