From baf74251936a7dc34870e1501303803f3e5ba693 Mon Sep 17 00:00:00 2001 From: AVMG20 Date: Fri, 12 Nov 2021 17:01:32 +0100 Subject: [PATCH] automatically select first options if there is only 1 --- resources/views/servers/create.blade.php | 75 ++++++++++++++++-------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/resources/views/servers/create.blade.php b/resources/views/servers/create.blade.php index 31071fec..59109edd 100644 --- a/resources/views/servers/create.blade.php +++ b/resources/views/servers/create.blade.php @@ -101,7 +101,7 @@ name="nest" id="nest" x-model="selectedNest" - @change="setNests();"> + @change="setEggs();"> @foreach ($nests as $nest) @@ -230,28 +230,33 @@ class="text-muted"> @@ -315,7 +320,7 @@ * @note called whenever a nest is selected * @see selectedNest */ - setNests() { + async setEggs() { this.fetchedLocations = false; this.fetchedProducts = false; this.locations = []; @@ -325,6 +330,14 @@ this.selectedProduct = 'null'; this.eggs = this.eggsSave.filter(egg => egg.nest_id == this.selectedNest) + + //automatically select the first entry if there is only 1 + if (this.eggs.length === 1) { + this.selectedEgg = this.eggs[0].id; + await this.fetchLocations(); + return; + } + this.updateSelectedObjects() }, @@ -347,6 +360,14 @@ this.fetchedLocations = true; this.locations = response.data + + //automatically select the first entry if there is only 1 + if (this.locations.length === 1 && this.locations[0]?.nodes?.length === 1) { + this.selectedNode = this.locations[0].id; + await this.fetchProducts(); + return; + } + this.loading = false; this.updateSelectedObjects() }, @@ -367,6 +388,12 @@ this.fetchedProducts = true; this.products = response.data + + //automatically select the first entry if there is only 1 + if (this.products.length === 1) { + this.selectedProduct = this.products[0].id; + } + this.loading = false; this.updateSelectedObjects() },