0

我得到错误:TypeError: Cannot read property 'length' of undefined

例如我有这个验证:

const agreementDurationAmount = Yup.number().when('agreementDuration', (agreementDuration) => {
  if(agreementDuration === 'Miesięczny') {
    return Yup.number().min(1, 'Czas trwania umowy: wprowadź liczbę miesięcy');
  }
  if(agreementDuration === 'Tygodniowy') {
    return Yup.number().min(1, 'Czas trwania umowy: wprowadź liczbę tygodni');
  }
  return Yup.number();
});

而这样的对象:

{
  agreementDuration: 'Nieokreślony',
  agreementDurationAmount: 0,
}

更大的错误信息:

formik.es6.js:377 Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
    at yupToFormErrors (formik.es6.js:377)
    at formik.es6.js:167
    at <anonymous>
  | yupToFormErrors | @ | formik.es6.js:377
-- | -- | -- | --
  | (anonymous) | @ | formik.es6.js:167
  | Promise rejected (async) |   |  
  | Formik._this.runValidationSchema | @ | formik.es6.js:161
  | Formik._this.submitForm | @ | formik.es6.js:262
  | Formik._this.handleSubmit | @ | formik.es6.js:234
  | ReactErrorUtils.invokeGuardedCallback | @ | ReactErrorUtils.js:69
  | executeDispatch | @ | EventPluginUtils.js:85
  | executeDispatchesInOrder | @ | EventPluginUtils.js:108
  | executeDispatchesAndRelease | @ | EventPluginHub.js:43
  | executeDispatchesAndReleaseTopLevel | @ | EventPluginHub.js:54
  | forEachAccumulated | @ | forEachAccumulated.js:24
  | processEventQueue | @ | EventPluginHub.js:254
  | runEventQueueInBatch | @ | ReactEventEmitterMixin.js:17
  | handleTopLevel | @ | ReactEventEmitterMixin.js:27
  | handleTopLevelImpl | @ | ReactEventListener.js:72
  | batchedUpdates | @ | ReactDefaultBatchingStrategy.js:60
  | batchedUpdates | @ | ReactUpdates.js:97
  | dispatchEvent | @ | ReactEventListener.js:147
  | componentDidUpdate | @ | App.jsx:17
  | measureLifeCyclePerf | @ | ReactCompositeComponent.js:75
  | (anonymous) | @ | ReactCompositeComponent.js:728
  | notifyAll | @ | CallbackQueue.js:76
  | close | @ | ReactReconcileTransaction.js:80
  | closeAll | @ | Transaction.js:209
  | perform | @ | Transaction.js:156
  | perform | @ | Transaction.js:143
  | perform | @ | ReactUpdates.js:89
  | flushBatchedUpdates | @ | ReactUpdates.js:172
  | closeAll | @ | Transaction.js:209
  | perform | @ | Transaction.js:156
  | batchedUpdates | @ | ReactDefaultBatchingStrategy.js:62
  | enqueueUpdate | @ | ReactUpdates.js:200
  | enqueueUpdate | @ | ReactUpdateQueue.js:24
  | enqueueSetState | @ | ReactUpdateQueue.js:218
  | ReactComponent.setState | @ | ReactBaseClasses.js:64
  | onStateChange | @ | connectAdvanced.js:205
  | dispatch | @ | createStore.js:173
  | dispatch | @ | VM33975:2
  | (anonymous) | @ | index.js:14
  | dispatch | @ | applyMiddleware.js:35
  | saveData.then.data | @ | index.js:129
  | Promise resolved (async) |   |  
  | (anonymous) | @ | index.js:102
  | (anonymous) | @ | index.js:11
  | dispatch | @ | VM33975:2
  | initStore.then.initialState | @ | getStore.js:109
  | Promise resolved (async) |   |  
  | getStore | @ | getStore.js:99
  | __webpack_exports__.a | @ | index.jsx:13
  | map../af | @ | main.js:39
  | __webpack_require__ | @ | bootstrap 4fef064…:19
  | Object.defineProperty.value | @ | bundle.js?1504015496728=123:55068
  | __webpack_require__ | @ | bootstrap 4fef064…:19
  | (anonymous) | @ | bootstrap 4fef064…:62
  | (anonymous) | @ | bootstrap 4fef064…:62
4

0 回答 0