This commit is contained in:
@@ -16,6 +16,9 @@ function addDataKeyNames(obj) {
|
||||
}
|
||||
|
||||
export default {
|
||||
// cache the form customization data if it's not already present
|
||||
//cache invalidation is hard, this needs it...hmmm....
|
||||
//for now will rely on logout and back in to clear up any customization issues
|
||||
get(formKey) {
|
||||
return new Promise(function getFormTemplate(resolve) {
|
||||
if (
|
||||
|
||||
@@ -47,6 +47,21 @@ function isNumber(n) {
|
||||
//
|
||||
function getControl(vm, ref) {
|
||||
var ctrl = vm.$refs[ref];
|
||||
if (ctrl === undefined) {
|
||||
//it's either a sub field in custom fields component or it's a coding error
|
||||
var customFields = vm.$refs["customFields"];
|
||||
if (customFields !== undefined) {
|
||||
ctrl = customFields.$refs[ref];
|
||||
}
|
||||
}
|
||||
|
||||
//can't do it like this because during init undefined is normal apparently
|
||||
// if (ctrl === undefined && window.$gz.errorHandler.devMode()) {
|
||||
// debugger;
|
||||
// throw "DEV ERROR gzform::formState.getControl -> control ref of [" +
|
||||
// ref +
|
||||
// "] was not found in the form or in the custom fields";
|
||||
// }
|
||||
|
||||
return ctrl;
|
||||
}
|
||||
@@ -63,11 +78,12 @@ function getControlValue(ctrl) {
|
||||
// Get field name from control
|
||||
//
|
||||
function getControlLabel(ctrl) {
|
||||
if (window.$gz.errorHandler.developmentModeShowErrorsImmediately) {
|
||||
if (!ctrl.label) {
|
||||
throw "gzform:getControlLabel - the control has no label " + ctrl;
|
||||
}
|
||||
}
|
||||
// if (window.$gz.errorHandler.developmentModeShowErrorsImmediately) {
|
||||
// if (!ctrl.label) {
|
||||
// debugger;
|
||||
// throw "gzform:getControlLabel - the control has no label " + ctrl;
|
||||
// }
|
||||
// }
|
||||
return ctrl.label;
|
||||
}
|
||||
|
||||
@@ -82,16 +98,15 @@ function getErrorsForField(vm, ref) {
|
||||
return !o.target;
|
||||
});
|
||||
} else {
|
||||
|
||||
ret = window.$gz._.filter(vm.formState.serverError.details, function(o) {
|
||||
if (!o.target) {
|
||||
return false;
|
||||
}
|
||||
//server error fields are capitalized
|
||||
//server error fields are capitalized
|
||||
//client field names are generally lower case except for custom fields
|
||||
//so we need to normalize them all to lower case to match
|
||||
//they will always differ by more than case so this is fine
|
||||
console.log("getErrorsForField finding matches, comparing serverErrorField:["+o.target.toLowerCase() + "] to form field ref:["+ref.toLowerCase()+"]");
|
||||
// console.log("getErrorsForField finding matches, comparing serverErrorField:["+o.target.toLowerCase() + "] to form field ref:["+ref.toLowerCase()+"]");
|
||||
return o.target.toLowerCase() == ref.toLowerCase();
|
||||
});
|
||||
}
|
||||
@@ -134,6 +149,7 @@ export default {
|
||||
if (vm.formState.loading) {
|
||||
return false;
|
||||
}
|
||||
//debugger;
|
||||
var ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return false;
|
||||
@@ -324,10 +340,8 @@ export default {
|
||||
// Process and return server errors if any for form and field specified
|
||||
//
|
||||
serverErrors(vm, ref) {
|
||||
|
||||
//CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC
|
||||
if (window.$gz.errorHandler.devMode()) {
|
||||
|
||||
//make sure formState.serverErrors is defined on data
|
||||
if (!window.$gz._.has(vm, "formState.serverError")) {
|
||||
throw "DEV ERROR gzform::formState.serverErrors -> formState.serverError seems to be missing from form's vue data object";
|
||||
@@ -355,7 +369,6 @@ export default {
|
||||
|
||||
//check for errors if we have any errors
|
||||
if (!window.$gz._.isEmpty(vm.formState.serverError)) {
|
||||
|
||||
//First let's get the top level error code
|
||||
|
||||
var apiErrorCode = parseInt(vm.formState.serverError.code);
|
||||
@@ -443,7 +456,8 @@ export default {
|
||||
//
|
||||
onChange(vm, ref) {
|
||||
//xeslint-disable-next-line
|
||||
//console.log("GZFORM::onChange triggered!");
|
||||
//WidgetCustom2
|
||||
//console.log("GZFORM::onChange triggered for field " + ref);
|
||||
if (triggeringChange || vm.formState.loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,14 @@
|
||||
|
||||
<div>
|
||||
<v-row align-center justify-left row wrap>
|
||||
<!-- Here is what a template object looks like
|
||||
"template":"[
|
||||
{\"fld\":\"WidgetNotes\",\"required\":\"true\"},{\"fld\":\"WidgetCustom1\",\"hide\":\"false\",\"required\":\"false\",\"type\":\"datetime\"},
|
||||
{\"fld\":\"WidgetCustom2\",\"hide\":\"false\",\"required\":\"true\",\"type\":\"text\"},{\"fld\":\"WidgetCustom3\",\"hide\":\"false\",\"required\":\"false\",\"type\":\"number\"},
|
||||
{\"fld\":\"WidgetCustom4\",\"hide\":\"false\",\"required\":\"false\",\"type\":\"bool\"},{\"fld\":\"WidgetCustom5\",\"hide\":\"false\",\"required\":\"false\",\"type\":\"currency\"},
|
||||
{\"fld\":\"WidgetCustom6\",\"hide\":\"false\",\"required\":\"false\",\"type\":\"date\"},{\"fld\":\"WidgetCustom7\",\"hide\":\"false\",\"required\":\"false\",\"type\":\"time\"}]"
|
||||
Note that it mixes in regular stock form fields that the end user has set to required as well as the custom ones, we identify custom by the presence of the "type" property
|
||||
-->
|
||||
<template v-for="item in this.$store.state.formCustomTemplate[formKey]">
|
||||
<v-col
|
||||
v-if="item.type"
|
||||
@@ -38,13 +46,16 @@
|
||||
DATE and TIME CONTROL HERE
|
||||
</div>
|
||||
<div v-else-if="item.type === 'text'">
|
||||
{{ lt(item.fld) }}
|
||||
<v-textarea
|
||||
v-model="_self[item.dataKey]"
|
||||
:readonly="readOnly"
|
||||
:label="lt(item.fld)"
|
||||
:ref="item.fld"
|
||||
:error-messages="form().serverErrors(parentVM, item.fld)"
|
||||
:rules="[form().required(parentVM, item.fld)]"
|
||||
auto-grow
|
||||
clearable
|
||||
></v-textarea>
|
||||
|
||||
<!-- <v-textarea
|
||||
@@ -55,6 +66,10 @@
|
||||
ref="notes"
|
||||
@change="onChange('notes')"
|
||||
auto-grow
|
||||
|
||||
@change="onChange(item.fld)"
|
||||
|
||||
>
|
||||
></v-textarea> -->
|
||||
</div>
|
||||
<div v-else-if="item.type === 'number'">
|
||||
@@ -76,7 +91,7 @@
|
||||
</template>
|
||||
<script>
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/* xeslint-disable */
|
||||
/* eslint-disable */
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* v-if="item.hide == false"
|
||||
@@ -115,7 +130,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
c1: null,
|
||||
//c2: "Here is my WidgetCustom2 Data!",
|
||||
// c2: null, this was replaced with a computed property as will all others
|
||||
c3: null,
|
||||
c4: null,
|
||||
c5: null,
|
||||
@@ -155,11 +170,16 @@ export default {
|
||||
//nothing
|
||||
return window.$gz.form;
|
||||
},
|
||||
onChange(ref) {
|
||||
if (!this.parentVM.formState.loading && !this.parentVM.formState.readOnly) {
|
||||
window.$gz.form.onChange(this.parentVM, ref);
|
||||
}
|
||||
},
|
||||
GetValueForField: function(dataKey) {
|
||||
if (!this.value) {
|
||||
return null;
|
||||
}
|
||||
// debugger;
|
||||
//debugger;
|
||||
//get the data out of the JSON string value
|
||||
var cData = JSON.parse(this.value);
|
||||
|
||||
@@ -169,20 +189,29 @@ export default {
|
||||
//coerce it to that type and return it
|
||||
//TODO: Method here
|
||||
|
||||
// debugger;
|
||||
|
||||
return cData[dataKey];
|
||||
},
|
||||
SetValueForField: function(dataKey, newValue) {
|
||||
//https://stackoverflow.com/questions/39868963/vue-2-mutating-props-vue-warn
|
||||
|
||||
//debugger;
|
||||
|
||||
//Get the data out of the json string value
|
||||
//
|
||||
var cData = JSON.parse(this.value);
|
||||
|
||||
//then set item in the cData
|
||||
//TODO: This will likely need also to be converted because dates and stuff
|
||||
//initial naive attempt: (tostring is suspect)
|
||||
cData[dataKey] = newValue.toString();
|
||||
//handle null or undefined
|
||||
if (newValue === null || newValue === undefined) {
|
||||
cData[dataKey] = null;
|
||||
} else {
|
||||
|
||||
//then set item in the cData
|
||||
|
||||
//TODO: This will likely need also to be converted because dates and stuff
|
||||
//initial naive attempt: (tostring is suspect)
|
||||
cData[dataKey] = newValue.toString();
|
||||
}
|
||||
|
||||
//emit the new data so it syncs with the parent source
|
||||
var ret = JSON.stringify(cData);
|
||||
@@ -203,10 +232,6 @@ export default {
|
||||
throw "custom-fields-control: $gz.locale is required and missing";
|
||||
}
|
||||
}
|
||||
|
||||
//trigger the template fetch
|
||||
|
||||
//var v=this.$store.state.formCustomTemplate[this.formKey];
|
||||
},
|
||||
created() {
|
||||
// console.log("custom-fields-control::BEFORECREATE: TOP");
|
||||
|
||||
@@ -147,6 +147,7 @@
|
||||
ref="notes"
|
||||
@change="onChange('notes')"
|
||||
auto-grow
|
||||
clearable
|
||||
></v-textarea>
|
||||
</v-col>
|
||||
|
||||
@@ -235,11 +236,10 @@ export default {
|
||||
"WidgetCustom16"
|
||||
];
|
||||
|
||||
window.$gz.locale
|
||||
.fetch(ltKeysRequired)
|
||||
.then(
|
||||
window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY).then(next())
|
||||
);
|
||||
window.$gz.locale.fetch(ltKeysRequired).then(
|
||||
//ensure cached any form customizations for this particular form
|
||||
window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY).then(next())
|
||||
);
|
||||
|
||||
// //very important as this in conjunction with the menu options means
|
||||
// //navigation guards work properly by just sending people here
|
||||
@@ -276,7 +276,7 @@ export default {
|
||||
valid: true,
|
||||
loading: false,
|
||||
readOnly: readOnly
|
||||
});
|
||||
});
|
||||
|
||||
//it's a new record so it can't be deleted so...
|
||||
this.rights.delete = false;
|
||||
|
||||
Reference in New Issue
Block a user