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.
 
 
 
 
 

91 lines
2.6 KiB

<urban-bucket-form>
<div class="form">
<form method="POST">
<input type="hidden" name="_token" value={ state.csrfToken } if={ state.csrfToken } />
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label" for="title">
title
</label>
</div>
<div class="field-body">
<div class="field">
<p class="control">
<input id="title" class={ getClasses('title', 'input') } type="text" name="title" value={ props.title } onkeyup={ (event) => { state.validator.handle(event, 'title') }} />
<field-error errors={ state.validator.errors('title') } ></field-error>
</p>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label" for="public">
public
</label>
</div>
<div class="field-body">
<div class="field">
<input id="public" type="checkbox">
</div>
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-primary" type="submit" disabled={ state.validator.errors().length > 0 }>
Create
</button>
</div>
</div>
</form>
</div>
<script>
import Validator from '@tentakelfabrik/tiny-validator/src/validator'
import FieldError from '../field-error.riot'
riot.register('field-error', FieldError)
/**
*
*
*
*/
export default {
onBeforeMount(props, state) {
state.validator = new Validator({
title: {
presence: true
}
}, this)
//
const meta = document.querySelector("meta[name='csrf-token']")
if (meta) {
state.csrfToken = meta.getAttribute("content")
}
},
getClasses(key, defaultClass) {
const classes = [
defaultClass
]
console.log(this.state.validator)
if (this.state.validator.errors(key).length > 0) {
classes.push('is-danger')
}
return classes.join(' ')
}
}
</script>
</urban-bucket-form>