Get validation messages working

This commit is contained in:
nathan 2022-02-24 10:35:53 -07:00
parent c83b281aa9
commit ce84dd753a
3 changed files with 42 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import {et2_IInput, et2_IInputNode} from "../et2_core_interfaces"; import {et2_IInput, et2_IInputNode} from "../et2_core_interfaces";
import {Et2Widget} from "../Et2Widget/Et2Widget"; import {Et2Widget} from "../Et2Widget/Et2Widget";
import {dedupeMixin} from "@lion/core"; import {dedupeMixin} from "@lion/core";
import {ManualMessage} from "./ManualMessage";
/** /**
* This mixin will allow any LitElement to become an Et2InputWidget * This mixin will allow any LitElement to become an Et2InputWidget
@ -188,9 +189,31 @@ const Et2InputWidgetMixin = (superclass) =>
return this._inputNode; return this._inputNode;
} }
transformAttributes(attrs)
{
super.transformAttributes(attrs);
// Check whether an validation error entry exists
if(this.id && this.getArrayMgr("validation_errors"))
{
let val = this.getArrayMgr("validation_errors").getEntry(this.id);
if(val)
{
this.set_validation_error(val);
}
}
}
set_validation_error(err : string) set_validation_error(err : string)
{ {
// ToDo, just a stub to silence TypeErrors // ToDo - implement Lion validators properly, most likely by adding to this.validators
// Need to change interaction state so messages show up
this.prefilled = true;
// Add validator
this.validators.push(new ManualMessage(err));
// Force a validate - not needed normally, but if you call set_validation_error() manually,
// it won't show up without validate()
this.validate();
} }
} }

View File

@ -0,0 +1,17 @@
import {ResultValidator} from "@lion/form-core";
/**
* Manual validator for server-side validation messages passed
* from Etemplate. It is always "activated", and just gives whatever
* message is passed in when created.
*
*/
export class ManualMessage extends ResultValidator
{
static validatorName = "ManualMessage";
static async getMessage({fieldName, modelValue, formControl, params})
{
return params;
}
}

View File

@ -57,6 +57,7 @@
"@bundled-es-modules/pdfjs-dist": "^2.5.207-rc1", "@bundled-es-modules/pdfjs-dist": "^2.5.207-rc1",
"@lion/button": "^0.14.2", "@lion/button": "^0.14.2",
"@lion/core": "^0.18.2", "@lion/core": "^0.18.2",
"@lion/form-core": "^0.15.1",
"@lion/input": "^0.15.4", "@lion/input": "^0.15.4",
"@lion/input-date": "^0.12.6", "@lion/input-date": "^0.12.6",
"@lion/input-datepicker": "^0.23.6", "@lion/input-datepicker": "^0.23.6",