You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
990 B

3 years ago
  1. <field-error>
  2. <div class="field-error" if={ state.errors.length > 0 }>
  3. <ul>
  4. <li class="help is-danger" each={ error in state.errors }>{ error }</li>
  5. </ul>
  6. </div>
  7. <script>
  8. /**
  9. * Shows errors of Validation
  10. *
  11. * <field-error key="name" errors={ errors }></field-error>
  12. *
  13. */
  14. export default {
  15. state: {
  16. errors: [
  17. ]
  18. },
  19. /**
  20. * check if errors from props has an error, if not reset errors in state
  21. *
  22. * @param {object} props
  23. * @param {object} state
  24. *
  25. */
  26. onBeforeUpdate(props, state) {
  27. if (props.errors && props.errors.length > 0) {
  28. state.errors = props.errors
  29. } else {
  30. state.errors = []
  31. }
  32. }
  33. }
  34. </script>
  35. </field-error>