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.

108 lines
3.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <urban-bucket-form>
  2. <div class="form">
  3. <form method="POST">
  4. <input type="hidden" name="_token" value={ state.csrfToken } if={ state.csrfToken } />
  5. <!-- title -->
  6. <div class="field is-horizontal">
  7. <div class="field-label is-normal">
  8. <label class="label" for="title">
  9. title
  10. </label>
  11. </div>
  12. <div class="field-body">
  13. <div class="field">
  14. <p class="control">
  15. <input id="title" class={ getClasses('title', 'input') } type="text" name="title" value={ props.title } onkeyup={ (event) => { state.validator.handle(event, 'title') }} />
  16. <field-error errors={ state.validator.errors('title') } ></field-error>
  17. </p>
  18. </div>
  19. </div>
  20. </div>
  21. <!-- is public -->
  22. <div class="field is-horizontal">
  23. <div class="field-label is-normal">
  24. <label class="label" for="public">
  25. public
  26. </label>
  27. </div>
  28. <div class="field-body">
  29. <div class="field">
  30. <input id="public" type="checkbox" name="public" value="1" checked={ props.public }>
  31. </div>
  32. </div>
  33. </div>
  34. <!-- submit -->
  35. <div class="field">
  36. <div class="control">
  37. <button class="button is-primary" type="submit" disabled={ state.validator.errors().length > 0 }>
  38. Create
  39. </button>
  40. </div>
  41. </div>
  42. </form>
  43. </div>
  44. <script>
  45. import Validator from '@tentakelfabrik/tiny-validator/src/validator'
  46. import FieldError from '../field-error.riot'
  47. riot.register('field-error', FieldError)
  48. /**
  49. *
  50. *
  51. *
  52. */
  53. export default {
  54. /**
  55. *
  56. * @param {[type]} props [description]
  57. * @param {[type]} state [description]
  58. *
  59. */
  60. onBeforeMount(props, state) {
  61. state.validator = new Validator({
  62. title: {
  63. presence: true
  64. }
  65. }, this)
  66. //
  67. const meta = document.querySelector("meta[name='csrf-token']")
  68. if (meta) {
  69. state.csrfToken = meta.getAttribute("content")
  70. }
  71. },
  72. /**
  73. *
  74. *
  75. * @param {[type]} key
  76. * @param {[type]} defaultClass
  77. * @return {[type]}
  78. *
  79. */
  80. getClasses(key, defaultClass) {
  81. const classes = [
  82. defaultClass
  83. ]
  84. const errors = this.state.validator.errors(key)
  85. if (errors && errors.length > 0) {
  86. classes.push('is-danger')
  87. }
  88. return classes.join(' ')
  89. }
  90. }
  91. </script>
  92. </urban-bucket-form>