jurassix / react-validation-mixin

Simple validation mixin (HoC) for React.
MIT License
283 stars 38 forks source link

How to implement react-validation-mixin with es6 code standard ? #27

Closed sijo-vijayan closed 9 years ago

sijo-vijayan commented 9 years ago

Hi, I am a newcomer in ReactJs, I would like to use react-validation-mixin in my project. But i don't know how to use it with ES6 standard. Can you update the README.md with ES6. This will be very helpful for people like me. Your help will be highly appreciated.

Thanks Sijo

sebinsua commented 9 years ago

This might not be the canonical response, but the library react-mixin works for me.

I use it without the decorators mode as I believe that is too cutting edge and I worry that the implementation might change in future.

I think the benefit to using a library is that you have something which can easily be removed if better support arrives in react or react-validation-mixin.

sijo-vijayan commented 9 years ago

@sebinsua Let me try this library. I have one more doubt, Where should I place the code given below in my react component class ? There is any syntax changes ?

  displayName: 'Signup',
  mixins: [ValidationMixin, React.addons.LinkedStateMixin],
  validatorTypes:  {
    firstName: Joi.string().required().label('First Name'),
    lastName: Joi.string().allow(null).label('Last Name'),
    email: Joi.string().email().label('Email Address'),
    username:  Joi.string().alphanum().min(3).max(30).required().label('Username'),
    password: Joi.string().regex(/[a-zA-Z0-9]{3,30}/).label('Password'),
    verifyPassword: Joi.any().valid(Joi.ref('password')).required().label('Password Confirmation')
  },
  getInitialState: function() {
    return {
      firstName: null,
      lastName: null,
      email: null,
      username: null,
      password: null,
      verifyPassword: null,
      feedback: null
    };
  },
jurassix commented 9 years ago

@sijo-vijayan - I've been waiting till I hit a next major release to enhance this library for ES6/7 support. I'll see if I can provide a simple top level API that you can use in the interim.

sijo-vijayan commented 9 years ago

@jurassix Thank you for your kind reply. :)

jurassix commented 9 years ago

ES6 (and ES7) are first class citizens now.

Documentation for 5.0