What I want to build is a Form which can detect errors from its Inputs. The inputs are rendered (in my current setup) in a section in the form. But after hours of work, it doesn't work.
What is the best approach to make the concept will work? Should I used slots for this or is there a other way?
This is my code:
//Form.vue
<template>
<form method="POST" action="/projects">
<slot></slot>
<div class="control">
<button class="button is-primary">Create</button>
</div>
</template>
<script>
import {FormHelper} from './classes/FormHelper.js';
export default {
/*
* The component's properties.
*/
props: {
fields: Object
},
data() {
return {
form: new FormHelper(this.fields) //this must be kwown in the Input.
};
},
}
</script>
//Input.vue
<template>
<div class="control">
<label for="name" class="label">{{label}}</label>
<input type="text" id="name" name="name" class="input">
<!--<span class="help is-danger" v-if="form.errors.has('name')" v-text="form.errors.get('name')"></span>-->
</div>
</template>
<script>
export default{
/*
* The component's properties.
*/
props: {
placeholder: String,
label: String,
name: String,
originalValue: String,
},
}
</script>
Implementation in the browser:
<vue-form :fields="{'name': 'piet', 'description': 'arie'}">
<vue-input
label="The Name"
name="name"
></vue-input>
<vue-input
label="The Description"
name="description"
></vue-input>
</vue-form>