tracking-code-which-will-go-to-the-HEAD FLAMEAL Documentation client/src/components/TransferForm/validateInfo.js

Source

client/src/components/TransferForm/validateInfo.js

  1. /**
  2. * Function used to validate the input of the list form from the ListFill component
  3. * @category Transfer
  4. * @function validateInfo
  5. * @param {Object} values - the input to be validated
  6. * @returns {Array} the array of errors found
  7. */
  8. export default function validateInfo(values) {
  9. //create an empty array
  10. let errors = {};
  11. if (!values.address) {
  12. //if the address field is empty update error
  13. errors.address = "Address required";
  14. } else if (values.address.length < 42) {
  15. //if the address is too short update error
  16. errors.address = "Adddres must be x caracters or more";
  17. }
  18. if (!values.comments) {
  19. //if the comments field is empty update error
  20. errors.comments = "Comment required";
  21. } else if (values.comments.length > 100) {
  22. //setting the error in case the comment is over 100 caracters
  23. //to prevent overloading the blockchain network
  24. errors.item = "Item name too long";
  25. }
  26. if (!values.itemsList || values.itemsList.length === 0) {
  27. //if the list is empty update errors
  28. errors.itemsList = "There are no goods in the contract";
  29. }
  30. return errors;
  31. }