Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux-form submit buttom #254

Open
grisena opened this issue Jul 13, 2018 · 3 comments
Open

Redux-form submit buttom #254

grisena opened this issue Jul 13, 2018 · 3 comments

Comments

@grisena
Copy link

grisena commented Jul 13, 2018

No description provided.

@grisena
Copy link
Author

grisena commented Jul 13, 2018

import React, { Component } from 'react';
import { reduxForm } from 'redux-form';
import { createPost } from '../actions/index';

class PostsNew extends Component {
render() {
const { fields: {title, categories, content}, handleSubmit } = this.props;

return(
  <Form onSubmit ={ handleSubmit(this.props.createPost) }>
    <h3> Create A New Post </h3>
    <div className ={ `form-group ${ title.touched && title.invalid ? 'has-danger' : '' }`>
     <label> Title </label>
     <input type ="text" className="form-control" {...title} />
      <div className="text-help">
        {title.touched ? title.error : ''}
      </div>
    </div>

   <div className ={ `form-group ${ categories.touched && categories.invalid ? 'has-danger' : '' }`>
     <label> Categories </label>
     <input type ="text" className="form-control" {...categories} />
     <div className="text-help">
       {categories.touched ? categories.error : ''}
     </div>
    </div>

    <div className ={ `form-group ${ content.touched && content.invalid ? 'has-danger' : '' }`>
     <label> Content </label>
     <textarea type ="text" className="form-control" {...content} />
     <div className="text-help">
       {content.touched ? content.error : ''}
     </div>
    </div>

    <button type="submit" className="btn btn-primary"> Submit </button>
  </Form>
);

}
}
function validate(values){
const errors ={};

if(!values.title) {
errors.title = 'Enter a username';
}

if(!values.categories) {
errors.categories = 'Enter categories';
}

if(!values.content) {
errors.content = 'Enter some content';
}
return errors;

}

export default reduxForm ({

form: 'PostsNewForm',
fields: ['title','categories','content'],
validate,
onSubmit: () => { }
},null,{createPost}) (PostsNew);

HELP PLEASE!!!
Submit button seems to not work and also the validation.

@grisena grisena changed the title Redux-form Redux-form submit buttom Jul 13, 2018
@grisena grisena closed this as completed Jul 13, 2018
@grisena grisena reopened this Jul 13, 2018
@justlearncode
Copy link

use version "redux-form": "^5.3.6", it will definately solve the problem

@justlearncode
Copy link

justlearncode commented Aug 4, 2018

You have another error in
<div className ={ form-group ${ title.touched && title.invalid ? 'has-danger' : '' }>
CHANGE TO
<div className ={ form-group ${ title.touched && title.invalid ? 'has-danger' : '' }}>
You forget }

CODE: posts_new.js IN LINE{23, 33, 43}
https://github.com/justlearncode/react-redux-add-postsReduxSimpleStarter-issues-254/blob/master/posts_new.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants