FaridSafi / react-native-gifted-form

📝 « One React-Native form component to rule them all »
MIT License
1.44k stars 214 forks source link

Without "defaults" form crashes on submit #90

Closed lukejagodzinski closed 7 years ago

lukejagodzinski commented 7 years ago

When I try to submit form without defaults and with empty fields I get the This library (validator.js) validates strings only error. I assume that this bug is caused by form values being undefined on form init. So after not focusing or changing form input it will try to validate undefined values. Solution could be copying all inputs' values at form init.

simulator screen shot 18 nov 2016 16 11 51

ktroach commented 7 years ago

Needs to have a null check on strings prior to asserting the length of the string. This occurs when when a value is not provided in clonedArgs[0] in the GiftedFormManager. Specifically, the clonedArgs[0] value is null. As a result, the validator library throws an exception when validation is applied.

To temporarily work around this issue, you can add a try/catch statement in the GiftedFormManager, like so:

  try {
    isValid = validatorjs[validate[i].validator].apply(null, clonedArgs);
    result.push({
      validator: validate[i].validator,
      isValid,
      message,
      value: clonedArgs[0],
      title: title || k,
    });
  } catch(exception) {
    console.log(exception);
  }

Keep in mind that this is just a temporary workaround and not a permanent solution. It does allow the validation to work on the form and prevents a redbox on submit.

arberkryeziu commented 7 years ago

+1

UPDATE: One solution is to ocupy the default values with empty strings eg.

defaults={{
          password:'',
          emailAddress:'',
}}
cooperka commented 7 years ago

This is a verified issue, thank you! A PR would be welcome if anyone wants to tackle this.

frmdstryr commented 7 years ago

https://github.com/frmdstryr/react-native-gifted-form/commit/68c1b5ebbdc1efae5116d298ddcb6783d35578c8

Fixes the validation errors. I'm still having issues with the date being reflected properly when selected (not sure if this is another issue or related at the moment).

cooperka commented 7 years ago

@frmdstryr I've fixed it and released v0.0.15, please try again :) The date seems to be working for me on the example app.

frmdstryr commented 7 years ago

Yep, working good now. Thanks!