Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. src/
  2. --/views
  3. --validations.js
  4. --/users
  5. --UserCreate.js
  6.  
  7. import {
  8. required,
  9. minLength,
  10. maxLength,
  11. minValue,
  12. maxValue,
  13. number,
  14. regex,
  15. email,
  16. choices
  17. } from 'react-admin';
  18.  
  19. export const required = () => required("Campo obrigatório")
  20. export const minLength = (value) => minLength(value,"Este campo deve ter o minimo de "+value+" caracteres")
  21. export const maxLength = (value) => maxLength("Este campo deve ter o máximo de "+value+" caracteres")
  22. export const email = () => email("Digite um e-mail válido")
  23. export const passwordsMatch = (value, allValues) => value !== allValues.password ? 'As senhas não coincidem' : undefined;
  24.  
  25. import React, { Component } from 'react';
  26. import { Create, SimpleForm, TextInput, DisabledInput } from 'react-admin';
  27. import { required, email, minLength,maxLength } from './../validations';
  28.  
  29.  
  30. export const UserCreate = props => (
  31. <Create {...props}>
  32. <SimpleForm redirect="list">
  33. <DisabledInput label="#" source="id" />
  34. <TextInput source="name" validate={[required(),minLength(5),maxLength(20)]} label="Nome"/>
  35. <TextInput source="email" validate={[required(),minLength(5),maxLength(20),email()]} label="E-mail"/>
  36. <TextInput source="password" validate={[required(),minLength(8),maxLength(20)]} label="Senha" type="password"/>
  37. <TextInput name="confirm_password" validate={[passwordsMatch]} label="Confirmar senha" type="password"/>
  38. </SimpleForm>
  39. </Create>
  40. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement