question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: func is not a function on Validation Rule Set

See original GitHub issue

Environment

  • OS: OS X 10.13.6
  • Node: 8.11
  • NPM: 5.6
  • react-advanaced-form: 1.5.0

What

Having a small problem that I can’t seem to nail down. I can’t even reproduce it on code sandbox, but can do it when I pull down a brand new create-react-app. When creating a field rule via the name property, on render I’m getting:

Uncaught TypeError: func is not a function
    at dispatch (index.development.js:24394)
    at flushFieldRefs (index.development.js:24892)
    at index.development.js:25090
    at _map (index.development.js:2367)
    at map (index.development.js:2760)
    at index.development.js:2221
    at index.development.js:1770
    at f1 (index.development.js:1636)
    at getRulesRefs (index.development.js:25094)
    at Object.createRulesSubscriptions (index.development.js:27243)
    at index.development.js:22207
    at Array.forEach (<anonymous>)

It looks like at https://github.com/kettanaito/react-advanced-form/blob/a00a08bfcab9a7427f38f383874445a99ac98a7c/src/utils/dispatch.js#L6

this function is going over the rules. When inspecting func, I’m getting back {someValidationFunction}, then `func(args) throws the above error.

This happens when I have something like

validation-rules.js

import isEmail from 'validator/lib/isEmail'
import isAlphanumeric from 'validator/lib/isAlphanumeric';
export default {
  type: {
    email: ({ value }) => isEmail(value),
    password: {
      capitalLetter: ({ value }) => /[A-Z]/.test(value),
      oneNumber: ({ value }) => /[0-9]/.test(value),
      minLength: ({ value }) => value.length > 5,
    },
  },

  name: {
    first_name: {
      isAlphanumeric: ({ value }) => value.length > 5,
    },
  },
}

when

Current behavior

Field cannot render and does not function when giving it the correct name property.

Expected behavior

This should render the field and create the field with it’s rules.

Why

I think this is something in a configuration, version of Webpack, babel but can’t find it myself ☹️ even after a few hours of swapping out versions.

How

Use the create-react-app and copy the code sandbox synchronous example. This I have been able to reproduce twice on the current 1.5.0 release. create-react-app@master.

If this can’t be solved it’s not a huge deal, as it seems to work great on another project! I just can’t nail down what might be causing this and though this might uncover something else otherwise.

Attached a project that should cause this issue as well! that might help!

react-advanced-form-broken-example.zip

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kettanaitocommented, Oct 9, 2018

Hi, @robertsonsamuel. I must say this is one of the greatest issue reports I’ve seen. Thank you for so detailed info and even your insights on what may cause this behavior.

I will investigate this when I have a spare minute and update this thread. Keep in touch.

1reaction
kettanaitocommented, Oct 9, 2018

I was able to reproduce the issue. It is unlikely that it relates to the configuration, but rather to the library itself. Will update once I have more info.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jquery validation plugin - TypeError - Stack Overflow
Jquery validation plugin - TypeError: $(...).validate is not a function ; type · "text/javascript" src="js/jquery-1.10.2.js"> ; type · "text/ ...
Read more >
TypeError: push is not a function in JavaScript | bobbyhadz
The "push is not a function" error occurs when the push() method is called on a value that is not an array. To...
Read more >
validate.js
Validate.js provides a declarative way of validating javascript objects. It is unit tested with 100% code coverage and can be considered fit for...
Read more >
TypeError: 'x' is not iterable - JavaScript - MDN Web Docs
When they are not called, the Function object corresponding to the generator is callable, but not iterable. Calling a generator produces an iterable...
Read more >
Untitled
TypeError : props. Hooks are JavaScript functions, but you need to follow two rules when using them. Aug 04, 2021 · The useState...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found