Used v-bind for text input updates

This commit is contained in:
Joel Collins 2019-01-28 16:43:08 +00:00
parent 4b935a5855
commit 0808f3708f

View file

@ -1,10 +1,11 @@
<template> <template>
<div class="host-input"> <div class="host-input">
<h2>Connect</h2>
<div class="uk-margin"> <div class="uk-margin">
<form @submit.prevent="handleSubmit"> <form @submit.prevent="handleSubmit">
<div class="uk-inline"> <div class="uk-inline">
<span class="uk-form-icon" uk-icon="icon: server"></span> <span class="uk-form-icon" uk-icon="icon: server"></span>
<input @input="IpChanged" v-bind:class="IpFormClasses" class="uk-input uk-form-width-medium uk-form-small" type="text" name="flavor" placeholder="localhost"> <input v-model="hostname" v-bind:class="IpFormClasses" class="uk-input uk-form-width-medium uk-form-small" type="text" name="flavor" placeholder="localhost">
</div> </div>
<button class="uk-button uk-button-default uk-form-small uk-float-right">Connect</button> <button class="uk-button uk-button-default uk-form-small uk-float-right">Connect</button>
<ul uk-accordion> <ul uk-accordion>
@ -13,14 +14,13 @@
<div class="uk-accordion-content"> <div class="uk-accordion-content">
<label class="uk-form-label" for="form-stacked-text">Port</label> <label class="uk-form-label" for="form-stacked-text">Port</label>
<div class="uk-form-controls"> <div class="uk-form-controls">
<input @input="portChanged" class="uk-input uk-form-width-medium uk-form-small" id="form-stacked-text" type="number" value=5000> <input v-model="port" class="uk-input uk-form-width-medium uk-form-small" id="form-stacked-text" type="number" value=5000>
</div> </div>
</div> </div>
</li> </li>
</ul> </ul>
</form> </form>
</div> </div>
</div> </div>
</template> </template>
@ -30,19 +30,13 @@ export default {
name: 'hostInput', name: 'hostInput',
methods: { methods: {
IpChanged: function(event) {
if (!(event.target.value == this.$store.state.host)) {
this.hostname = event.target.value
}
},
portChanged: function(event) {
this.port = event.target.value
},
handleSubmit: function(event) { handleSubmit: function(event) {
// Commit the hostname and port to store
this.$store.commit('changeHost', [ this.$store.commit('changeHost', [
this.hostname, this.hostname,
this.port this.port
]); ]);
// Try to get config JSON from the newly submitted host
this.$store.dispatch('updateConfig'); this.$store.dispatch('updateConfig');
} }
}, },
@ -55,6 +49,7 @@ export default {
}, },
computed: { computed: {
// Stylises the hostname input box based on connection status
IpFormClasses: function () { IpFormClasses: function () {
return { return {
'uk-form-danger': !this.$store.state.available, 'uk-form-danger': !this.$store.state.available,