field view validation functions

This commit is contained in:
Yuri Kuznetsov
2024-06-18 12:08:39 +03:00
parent 3f6f718cd9
commit 831d840cc5
12 changed files with 73 additions and 9 deletions
+4 -1
View File
@@ -58,7 +58,10 @@ class AddressFieldView extends BaseFieldView {
stateField
countryField
/** @inheritDoc */
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = [
'required',
'pattern',
+6
View File
@@ -87,7 +87,13 @@ class ArrayFieldView extends BaseFieldView {
searchTypeList = ['anyOf', 'noneOf', 'allOf', 'isEmpty', 'isNotEmpty']
maxItemLength = null
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = ['required', 'maxCount']
MAX_ITEM_LENGTH = 100
/**
@@ -82,11 +82,17 @@ class AttachmentMultipleFieldView extends BaseFieldView {
foreignScope
showPreviews = true
accept = null
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = [
'ready',
'required',
'maxCount',
]
searchTypeList = ['isNotEmpty', 'isEmpty']
events = {
+16 -5
View File
@@ -137,9 +137,12 @@ class BaseFieldView extends View {
editTemplateContent
/**
* A validation list. There should be a `validate{Name}` method for each item.
* A validation list. A function returning true if non-valid, or a name.
* For the latter, there should be a `validate{Name}` method in the class.
*
* @type {string[]}
* Functions are supported as of v8.4.
*
* @type {Array<(function (): boolean)|string>}
*/
validations = ['required']
@@ -1542,10 +1545,18 @@ class BaseFieldView extends View {
validate() {
this.lastValidationMessage = null;
for (const i in this.validations) {
const method = 'validate' + Espo.Utils.upperCaseFirst(this.validations[i]);
for (const item of this.validations) {
let notValid = false;
if (this[method].call(this)) {
if (typeof item === 'function') {
notValid = item();
} else {
const method = 'validate' + Espo.Utils.upperCaseFirst(item);
notValid = this[method].call(this);
}
if (notValid) {
this.trigger('invalid');
return true;
+4
View File
@@ -90,6 +90,10 @@ class CurrencyFieldView extends FloatFieldView {
maxDecimalPlaces = 3
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = [
'required',
'number',
+4
View File
@@ -71,6 +71,10 @@ class DateFieldView extends BaseFieldView {
editTemplate = 'fields/date/edit'
searchTemplate = 'fields/date/search'
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = [
'required',
'date',
+10 -1
View File
@@ -69,7 +69,16 @@ class DatetimeFieldView extends DateFieldView {
editTemplate = 'fields/datetime/edit'
validations = ['required', 'datetime', 'after', 'before']
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = [
'required',
'datetime',
'after',
'before',
]
searchTypeList = [
'lastSevenDays',
+6 -1
View File
@@ -70,9 +70,14 @@ class FloatFieldView extends IntFieldView {
editTemplate = 'fields/float/edit'
decimalMark = '.'
validations = ['required', 'float', 'range']
decimalPlacesRawValue = 10
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = ['required', 'float', 'range']
/** @inheritDoc */
setup() {
super.setup();
+5
View File
@@ -71,6 +71,11 @@ class IntFieldView extends BaseFieldView {
detailTemplate = 'fields/int/detail'
editTemplate = 'fields/int/edit'
searchTemplate = 'fields/int/search'
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = ['required', 'int', 'range']
thousandSeparator = ','
+4
View File
@@ -74,6 +74,10 @@ class LinkMultipleFieldView extends BaseFieldView {
editTemplate = 'fields/link-multiple/edit'
searchTemplate = 'fields/link-multiple/search'
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = [
'required',
'maxCount',
+4
View File
@@ -70,6 +70,10 @@ class UrlFieldView extends VarcharFieldView {
detailTemplate = 'fields/url/detail'
defaultProtocol = 'https:'
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = [
'required',
'valid',
+4 -1
View File
@@ -88,7 +88,10 @@ class VarcharFieldView extends BaseFieldView {
'isNotEmpty',
]
/** @inheritDoc */
/**
* @inheritDoc
* @type {Array<(function (): boolean)|string>}
*/
validations = [
'required',
'pattern',