This commit is contained in:
@@ -173,11 +173,61 @@ export default {
|
||||
//get the data out of the JSON string value
|
||||
var cData = JSON.parse(this.value);
|
||||
|
||||
//POtentially, down the road might need to co-erce the value to the right type, this is where that would happen
|
||||
//get the type it *should* be
|
||||
//coerce it to that type and return it
|
||||
//Custom field types can be changed by the user and cause old entered data to be invalid for that field type
|
||||
//Here we need to take action if the data is of an incompatible type for the control field type and attempt to coerce or simply nullify if not co-ercable the data
|
||||
// - CURRENT TEXT fields could handle any data so they don't need to be changed
|
||||
// - CURRENT BOOL fields can only handle empty or true false so they would need to be set null
|
||||
// - CURRENT TIME, DATE, DATETIME are pretty specific but all use a datetime string so any value not datetime like should be nulled
|
||||
// - CURRENT NUMBER, CURRENCY are also pretty specific but easy to identify if not fully numeric and then sb nulled or attempt to convert then null if not
|
||||
|
||||
return cData[dataKey];
|
||||
//Get the field data type
|
||||
//https://lodash.com/docs#find
|
||||
var ctrlType = window.$gz._.find(
|
||||
this.$store.state.formCustomTemplate[this.formKey],
|
||||
["dataKey", dataKey]
|
||||
).type;
|
||||
//console.log("Field with datakey " + dataKey + " is of type " + ctrlType);
|
||||
|
||||
//First get current value for the data that came from the server
|
||||
var ret = cData[dataKey];
|
||||
//Only process if value is non-null since all control types can handle null
|
||||
if (ret != null) {
|
||||
//check types that matter
|
||||
switch (ctrlType) {
|
||||
//DateLike?
|
||||
case "date":
|
||||
case "time":
|
||||
case "datetime":
|
||||
//can it be parsed into a date using the same library as the components use?
|
||||
if (!window.$gz.dayjs(ret).isValid()) {
|
||||
ret = null;
|
||||
}
|
||||
break;
|
||||
case "bool":
|
||||
//if it's not already a boolean
|
||||
if (!window.$gz._.isBoolean(ret)) {
|
||||
//it's not a bool and it's not null, it came from some other data type,
|
||||
//perhaps though, it's a truty string so check for that before giving up and nulling
|
||||
if (window.$gz._.isString(ret)) {
|
||||
ret = window.$gz.util.stringToBoolean(ret);
|
||||
break;
|
||||
}
|
||||
//The number 1?
|
||||
if (ret === 1) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
//The number 0?
|
||||
if (ret === 0) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//{"c1":"2019-01-27T09:26:06.1673391Z","c2":"Esse sunt re in.","c3":48824971,"c4":false,"c5":0.120971084628706}
|
||||
return ret;
|
||||
},
|
||||
SetValueForField: function(dataKey, newValue) {
|
||||
//Get the current data out of the json string value
|
||||
@@ -192,9 +242,6 @@ export default {
|
||||
cData[dataKey] = null;
|
||||
} else {
|
||||
//then set item in the cData
|
||||
|
||||
//POtentially, down the road might need to co-erce the value to the right type, this is where that would happen
|
||||
|
||||
cData[dataKey] = newValue.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user