Hi there fellow stackers, I recently came upon a problem that is quite literally halting my progress on the entire project.
Let's get to it; What needs to be done?
Basically, I have a dynamic form saying Label and Internal Name. I have the section ready where you can click the add button to add a new label and internal name input in the table, however, that was just part 1.
Part 2 is that the internal name input is not filled independantly; it is a realtime form which is supposed to take the input placed in label. So if I type "Hello world" in label, there should automatically also be a "hello world" in the internal name input box without me having typed there at all.
As soon as I started combining two vue.js fiddles, things started to go wrong. These fiddles are:
Dynamic form: https://jsfiddle.net/7nxhygLp/
Realtime form: https://jsfiddle.net/gtmmeak9/118/
Here is the HTML code for my page where it is displayed (includes the vue.js)
=========================================================
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>M06 Property-create</title>
<!-- Including nessecary javascript sources -->
<script src="https://unpkg.com/vue@next/dist/vue.js"></script>
</head>
{!! Form::open(array('route' => 'property.store')) !!}
@include('properties.form')
{!! Form::close() !!}
<a href="/property">Return</a>
<script> //This script handles the adding / removal of label/text fields upon clicking the add label / remove label button
var Component1 = Vue.extend({
template: 'Component 1: <input type="text" v-model="prop"/>',
props: ['prop']
});
var Component2 = Vue.extend({
template: 'Component 2: <input type="text" v-model="prop"/>',
props: ['prop']
});
var app = new Vue({
el: "#app",
data: {
rows: [
{label: "", internal_name: ""}
]
},
components: {
'comp1': Component1,
'comp2': Component2
}
methods: {
addRow: function () {
this.rows.push({label: ""});
},
removeRow: function (index) {
//console.log(index);
this.rows.splice(index, 1);
}
}
});
</script>
</body>
</html>
==========================================================
And here is the included form that at this moment is broken
==========================================================
{!! Form::label('field_type_id', Lang::get('misc.fieldtype_name')) !!}
{!! Form::select('field_type_id', $fieldTypes) !!}
<br>
<div class="dropdown box">
<div class="multi-field-wrapper">
<div class="multi-fields">
<div class="multi-field">
<div id="app">
<table class="table">
<thead>
<br>
<button type="button" class="button btn-primary" @click="addRow">Add label</button>
<br>
<tr>
<br>
<td><strong>Label</strong></td>
<td><strong>Internal Name</td>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in rows">
<td><input name="label" id="label" type="text" v-model="row.label"></td>
<td><input name="internal_name" id="internal_name" type="text" v-model="row.internal_name"></td>
<td><button type="button" class="button btn-primary" @click="removeRow(index)">Remove</button></td>
<td><comp1: prop.sync="input"></comp1></td>
<td><comp2: prop.sync="input"></comp2></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<br>
{!! Form::label('property_group_id', Lang::get('misc.group_name')) !!}
{!! Form::select('property_group_id', $groups) !!}
<br>
{!! Form::label('description', Lang::get('misc.description')) !!}
{!! Form::textarea('description', null, ['class' => 'form-control', 'required']) !!}
<br>
<br>
{!! Form::submit(Lang::get('misc.save'), ['class' => 'btn btn-success', 'id' => 'btn-save']) !!}