Skip to content

isFieldInError and getErrorsInField doesn't work and custom messages #72

@apilarteq

Description

@apilarteq

Hello, I'm trying to make conditionals with isFieldInError and getErrorsInField, but it returned me false and an empty array respectively even having errors, this is my code, I'm doing like a reusable component.

function RegisterForm({data}) {
  const [field, setField] = useState('');
  const [value] = useDebounce(field, 1000);

  const {validate, isFieldInError, getErrorsInField, getErrorMessages} =
    useValidation({
      state: {field},
    });

  const _validateForm = () => {
    validate({
      field: data.rules,
    });
  };

  React.useEffect(() => {
    if (value.length !== 0) {
      _validateForm();
    }
  }, [value]);

  return (
    <View style={tailwind('px-8')}>
      <TextInput
        placeholder={data.placeholder}
        style={[
          tailwind('text-black p-0 text-xl pb-1 flex-row'),
          {
            borderBottomWidth: 1,
            borderBottomColor: '#808080',
          },
        ]}
        onChangeText={text => setField(text)}
        value={field}
      />
      <Text>{getErrorMessages()}</Text>
      <TouchableOpacity onPress={() => _validateForm()}>
        <Text>auwhdauywd</Text>
      </TouchableOpacity>
    </View>
  );
}

And I want to use custom messages but I don't know how, please help me, thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions