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.

Cannot read property 'change' of undefined

See original GitHub issue
import { reduxForm, Field, actionCreators } from 'redux-form'
import Select from 'react-select'

<Select
            value="one"
            options={QT}
            {...input}
            onBlur={() => {
              input.onBlur({...input.value})
              dispatch(actionCreators.change('PostQuestionForm', 'title', input.value.type));
            }
          }
        />

I am trying to change another field value based on what the user select using Select component. If there is any other way to get this done i am open for suggestions. Also why its so hard to control the form state here is above me tbh because in simple controlled input (for example by using Alt.js) state is literally your bitch to manage like you can do anything with it and no one will shed a tear. or maybe im just new to redux and redux form.

but here is what i want to do, i have 2 input fields one one which is select field, now when i select something in the select field i want to put that value into the input field below and then i want to write something in the input field after the selected value also i want that input field value to not exceed certain amount of characters lets say 70 and i want to display the remaining character limit. Now if i were managing my own form state this would be 10 times easier and it took me very less effort when i implemented this logic using Alt.js some time ago.

here is my form component

import React from 'react'
import { reduxForm, Field, actionCreators } from 'redux-form'
import AuthB from 'AuthB'
import Select from 'react-select'
import 'react-select/dist/react-select.css';
import QT from './question-type'
require('./ask.scss')

const validate = values => {
    let errors = {}
    if(!values.title || values.title.length <= 0){
      errors.title = ' is required'
    } else if(values.title.length > 70){
      errors.title = ' is more than 70'
    }
    if(!values.description || values.title.length <= 0){
      errors.description = ' is required'
    } else if(values.description.length > 200){
      errors.description = ' is more than 200'
    }
    if(!values.type){
      errors.type = ' is required'
    }
    return errors
}

const renderTextarea = ({ input, label, type, meta: { touched,  error, warning } }) => {
  return(
    <div className="box">
      <label>
        {label}
        {touched && (error && <span className="control-label" htmlFor={label}>{error}</span>)}
      </label>
      <div className={
          (touched && error) ? input.name+'-box has-error' : input.name+'-box'
      }>
        <textarea type={type} id={label} {...input} placeholder={label} />
      </div>
    </div>
  )
}

const renderInput = ({ input, label, type, meta: { dispatch, touched, error, warning, submitting } }) => {
  let title = input.value
  return(
    <div className="box">
      <label>
        {label}
        {touched && (error && <span className="control-label" htmlFor={label}>{error}</span>)}
      </label>
      <div className={input.name+'-box'}>
        <input type={type} id={label} {...input} onChange={()=> input.onChange(title)} placeholder={label} />
      </div>
    </div>
  )
}

const renderSelect = ({input, label, type, meta: { dispatch, touched, error, warning } }) => {
  return (
    <div className="box">
      <label>
        {label}
        {touched && (error && <span className="control-label" htmlFor={label}>{error}</span>)}
      </label>
      <div className="select-box">
        <Select
            value="one"
            options={QT}
            {...input}
            onBlur={() => {
              input.onBlur({...input.value, hey:'whats'})
              dispatch(actionCreators.change('PostQuestionForm', 'title', 'cityValue'));
            }
          }
        />
      </div>
    </div>
  )
}

let QuestionForm = props => {
  const { dispatch, handleSubmit, invalid, submitting, error } = props
  const doSubmit = values => alert('hi')
  return(
    <form onSubmit={handleSubmit(doSubmit)}>
      <div className="group ask-wrapper">
        <div className="ask-heading">
          <h3>Have a question? Just ask...</h3>
          <h6>
              It is as important how you ask your question than what you are asking!
          </h6>
        </div>
        <hr/>
          <Field name="type" type="text" label="Select a starting phrase" component={renderSelect}/>
          <Field name="title" type="text" label="Question Title" component={renderInput}/>
          <Field name="description" type="text" label="Description" component={renderTextarea}/>
          <Field name="tag" type="text" label="Select tags" component={renderInput}/>
        <hr/>
        <div>
          <button disabled={submitting} type="submit">And thats it</button>
        </div>
        <div className="clearfix"></div>
      </div>
    </form>
  )
}

QuestionForm = reduxForm({
  form: 'PostQuestionForm',
  validate,
})(QuestionForm)

export default AuthB(QuestionForm)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
elmeistercommented, Dec 13, 2016

What about this.props.change('name', '')

0reactions
lock[bot]commented, Jun 2, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'change' of undefined
Simulate has been removed from react-testing-library. What you need to use today is fireEvent . You can use it in this way:
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError : Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an...
Read more >
ERROR TypeError: Cannot read property 'changes' of ... - GitHub
Hi, Recently in my project, I've updated angular-archwizard from 4.0.0 to 5.0.0 When I run ng serve everything works perfectly, ...
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
If a property of an object is an array, it's possible to accidentally misspell the key or try to access the array through...
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