Add error styling, and rename url to uri

This commit is contained in:
Oliver-Akins 2020-09-19 17:14:06 -06:00
parent 13b27056db
commit 703d03da3b

View file

@ -10,12 +10,14 @@
<input <input
type="text" type="text"
name="Websocket URL" name="Websocket URL"
v-model="ws_url" :class="has_error ? 'error' : ''"
@keyup.enter="submit_ws_url()" v-model="ws_uri"
@change.stop="has_error = false"
@keyup.enter="submit_ws_uri()"
> >
<br> <br>
<button <button
@onclick.stop="submit_ws_url()" @click.stop="submit_ws_uri()"
> >
Confirm URL Confirm URL
</button> </button>
@ -27,14 +29,17 @@ export default {
name: 'WebsocketEntry', name: 'WebsocketEntry',
components: {}, components: {},
data() {return { data() {return {
ws_url: ``, ws_uri: ``,
has_error: false,
ws_regex: /^(wss?|https?):\/\//,
}}, }},
methods: { methods: {
submit_ws_url() { submit_ws_uri() {
if (this.ws_url.length > 0 && this.ws_url.match(/^wss?:\/\//)) { if (this.ws_uri.length > 0 && this.ws_uri.match(this.ws_regex)) {
this.$emit(`set-ws-url`, this.ws_url); this.$emit(`try-ws-uri`, this.ws_uri);
} else { } else {
alert(`Invalid websocket URL, it must begin with "wss://" in order to connect.`) this.has_error = true;
alert(`Invalid websocket URL, please check that you typed it correctly.`)
} }
}, },
}, },