diff --git a/modules/farm_fd2/src/entrypoints/harvest/App.vue b/modules/farm_fd2/src/entrypoints/harvest/App.vue
index 98d4668c..3d20e2b9 100644
--- a/modules/farm_fd2/src/entrypoints/harvest/App.vue
+++ b/modules/farm_fd2/src/entrypoints/harvest/App.vue
@@ -14,16 +14,18 @@
id="harvest-date"
data-cy="harvest-date"
v-bind:required="true"
- v-bind:showValidityStyling="true"
+ v-bind:showValidityStyling="validity.show"
v-model:date="date"
+ v-on:valid="validity.date = $event"
/>
@@ -66,15 +68,18 @@
data-cy="harvest-quantity"
label="Quantity"
v-bind:required="true"
+ v-bind:showValidityStyling="validity.show"
v-bind:incDecValues="[1, 5]"
v-bind:minValue="1"
v-model:value="quantity"
+ v-on:valid="validity.quantity = $event"
/>
+
+
{{ unit.attributes.name }}
+ {{ unit.attributes.name }}
+
+
+
@@ -126,6 +136,7 @@ import CommentBox from '@comps/CommentBox/CommentBox.vue';
import SubmitResetButtons from '@comps/SubmitResetButtons/SubmitResetButtons.vue';
import * as farmosUtil from '@libs/farmosUtil/farmosUtil';
+
export default {
components: {
DateSelector,
@@ -144,16 +155,31 @@ export default {
comment: '',
plantList: [],
unitList: [],
+ validity: {
+ show: false,
+ date: null,
+ crop: null,
+ quantity: null,
+ comment: null,
+ },
+ submitting: false,
};
},
computed: {
- formValid() {
+ submitEnabled() {
+ return !this.validity.show || (this.validToSubmit && !this.submitting);
+ },
+ resetEnabled() {
+ return !this.submitting;
+ },
+ validToSubmit() {
return (
- this.date != '' &&
- this.crop != null &&
+ this.validity.date === true &&
+ this.validity.crop === true &&
this.pickedPlant != null &&
- this.quantity > 0 &&
- this.unit != null
+ this.validity.quantity === true &&
+ this.unit != null &&
+ this.validity.comment === true
);
},
sortedPlantList() {
@@ -164,6 +190,12 @@ export default {
},
methods: {
resetForm() {
+ this.validity.show = false;
+ this.validity.date = null;
+ this.validity.crop = null;
+ this.validity.quantity = null;
+ this.validity.comment = null;
+
this.date = '2019-06-15';
this.crop = null;
this.pickedPlant = null;
@@ -172,30 +204,39 @@ export default {
this.comment = '';
},
async submitForm() {
- let measure = '';
- if (this.unit.relationships.parent.length > 0) {
- const unitMap = await farmosUtil.getUnitIdToTermMap();
- const measureObj = unitMap.get(this.unit.relationships.parent[0].id);
- measure = measureObj.attributes.name;
- }
+ this.submitting = true;
+ this.validity.show = true;
- const quantity = await farmosUtil.createStandardQuantity(
- measure,
- this.quantity,
- 'harvest',
- this.unit.attributes.name
- );
+ if (this.validToSubmit) {
+ let measure = '';
+ if (this.unit.relationships.parent.length > 0) {
+ const unitMap = await farmosUtil.getUnitIdToTermMap();
+ const measureObj = unitMap.get(this.unit.relationships.parent[0].id);
+ measure = measureObj.attributes.name;
+ }
- const plantAsset = await farmosUtil.getPlantAsset(this.pickedPlant.uuid);
+ const quantity = await farmosUtil.createStandardQuantity(
+ measure,
+ this.quantity,
+ 'harvest',
+ this.unit.attributes.name
+ );
- await farmosUtil.createHarvestLog(
- this.date,
- this.pickedPlant.location,
- this.pickedPlant.beds,
- plantAsset,
- quantity,
- this.comment
- );
+ const plantAsset = await farmosUtil.getPlantAsset(
+ this.pickedPlant.uuid
+ );
+
+ await farmosUtil.createHarvestLog(
+ this.date,
+ this.pickedPlant.location,
+ this.pickedPlant.beds,
+ plantAsset,
+ quantity,
+ this.comment
+ );
+ }
+
+ this.submitting = false;
},
},
watch: {
@@ -211,7 +252,8 @@ export default {
const units = await farmosUtil.getHarvestUnits(this.crop);
this.unitList = units;
- if (this.unitList.length == 1) {
+
+ if (this.unitList.length === 1) {
this.unit = this.unitList[0];
} else {
this.unit = null;
@@ -219,6 +261,7 @@ export default {
} else {
this.plantList = [];
this.unitList = [];
+ this.unit = null;
}
},
},
@@ -226,7 +269,6 @@ export default {