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.

React Native AsyncValidation undefined values

See original GitHub issue

Hi, I’m Using React Native and I tried use AsyncValidation, but when asyncValidate is called the value of email Field is undefined, this happen when use asyncBlurFields, the fields entry in the vector are undefined

SignupForm Code

const validate = values => {
  const errors = {}
  if (!values.email) {
    errors.email = 'Campo requerido'
  } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
    errors.email = 'Email inválido'
  }
  if (!values.password) {
    errors.password = 'Campo requerido'
  }
  return errors
}

const asyncValidate = (values) => {
  const errors = {};
  console.log(values);
  return axios.get(`${api.uri}/auth/${values.email}/exists`)
    .then( res => {
      console.log(res);
    })
    .catch( err => {
      console.log(err);
    })
}

const SignupForm = ({
  onSwitch,
  submitting,
  error,
  handleSubmit,
  SignupServer, }) => {

  const ColoredRaisedButton = MKButton.coloredButton()
    .withBackgroundColor('orange')
    .withStyle(styles.submitButton)
    .build();

  return (
    <View style={[styles.signupForm]}>
      <Text style={styles.title}>Regístrate</Text>
      {error && <Text style={styles.error}>
        {error}
      </Text>}
      <Field
        name='email'
        label='Email'
        dense={true}
        component={TextField} />
      <Field
        name='password'
        label='Password'
        dense={true}
        isPassword={true}
        component={TextField} />
      <ColoredRaisedButton
        onPress={handleSubmit(SignupServer)}>
        { submitting ?
          <ActivityIndicator
            color="white"
            size={32} /> :
            <Text style={{color: 'white', fontWeight: 'normal', fontSize: 24,}}>Crear Cuenta</Text> }
      </ColoredRaisedButton>
    </View>
  )
} 
export default reduxForm({
  form: 'signup',
  validate,
  asyncValidate,
  asyncBlurFields: ['email'],
})(SignupForm)

TextField Component

class TextField extends Component {

  constructor(props){
    super(props)
  }

  render(){
    let {
      input: { value, onChange, onFocus, onBlur, ...restInput },
      meta: { asyncValidating, touched, error, invalid, active, visited },
      isPassword,
      label,
      duration,
      borderColor,
      dense,
      textColor,
      textFocusColor,
      ...props,
    } = this.props;
    if(touched && error){
      this.refs.underline.expandLine()
    }
    return (
      <View>
        <View style={[dense ? styles.denseWrapper : styles.wrapperInput]}>
          <TextInput
              style={[ dense ? styles.denseTextInput : styles.textInput, {
                color: textColor
              } : {}, (active && textFocusColor) ? {
                color: textFocusColor
              } : {},]}
              onChangeText={onChange}
              onFocus={(e) => {
                this.refs.label.floatLabel();
                this.refs.underline.expandLine();
                onFocus(e);
              }}
              onBlur={(e) => {
                !value.length ? this.refs.label.sinkLabel() : null;
                error ? this.refs.underline.expandLine() : this.refs.underline.shrinkLine() ;
                onBlur(e);
              }}
              secureTextEntry={isPassword ? isPassword : false}
              {...restInput}
              {...props} />
          <FloatingLabel
            ref='label'
            label={label}
            dense={dense}
            labelColor={'gray'}
            duration={duration}
            highlightColor={ touched && error ? 'red' : 'blue' }
            isFocused={ active ? true : active }
            hasValue={value ? true : false } />
          <Underline
            ref="underline"
            duration={duration}
            borderColor={'gray'}
            highlightColor={ touched && error ? 'red' : 'blue' } />
        </View>
        <View style={styles.wrapperErr}>
          {touched && (error && <Text style={styles.textErr}>{error}</Text>)}
        </View>
      </View>);
  }
}

alt text

When asyncValidate is called the value of email in the state is ‘test@test.cl’ but in the function is undefined, but if I change asyncBlurFields to password the result is

alt text

I’m using node 6.10.1, React Native 0.42.0 and Redux Form 6.6.3

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
kasterlodcommented, Apr 13, 2018

@dbelchev add this to your input component and pass as onBlur instead of the input from

onBlur = () => { const { input: { value, onBlur } } = this.props onBlur(value) }

0reactions
lock[bot]commented, Sep 11, 2019

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

Redux-form async validation returning undefined for fields in ...
If I then unFocus from firstname , the value of firstname will now be undefined while that of username will be present. Both...
Read more >
Async Blur Validation Example - Redux Form
The classic example of this letting someone choose a value, like a username, that must be unique within your system. To provide asynchronous...
Read more >
useForm - register - Simple React forms validation
For schema validation, you can leverage the undefined value returned from input or ... name is required and unique (except native radio and...
Read more >
React Final Form - Asynchronous Field-Level Validation ...
Forked From React Final Form - Asynchronous Field-Level Validation Example; Environmentcreate-react-app. Files. Spinner.js. Styles.js. index.js.
Read more >
JavaScript Validator Validation Rules - DevExtreme
Use async rules for server-side validation. ... You can also set a custom message, specify whether empty values are valid, and whether the...
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