field view validation functions
This commit is contained in:
@@ -58,7 +58,10 @@ class AddressFieldView extends BaseFieldView {
|
||||
stateField
|
||||
countryField
|
||||
|
||||
/** @inheritDoc */
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @type {Array<(function (): boolean)|string>}
|
||||
*/
|
||||
validations = [
|
||||
'required',
|
||||
'pattern',
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -90,6 +90,10 @@ class CurrencyFieldView extends FloatFieldView {
|
||||
|
||||
maxDecimalPlaces = 3
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @type {Array<(function (): boolean)|string>}
|
||||
*/
|
||||
validations = [
|
||||
'required',
|
||||
'number',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 = ','
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -70,6 +70,10 @@ class UrlFieldView extends VarcharFieldView {
|
||||
detailTemplate = 'fields/url/detail'
|
||||
defaultProtocol = 'https:'
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @type {Array<(function (): boolean)|string>}
|
||||
*/
|
||||
validations = [
|
||||
'required',
|
||||
'valid',
|
||||
|
||||
@@ -88,7 +88,10 @@ class VarcharFieldView extends BaseFieldView {
|
||||
'isNotEmpty',
|
||||
]
|
||||
|
||||
/** @inheritDoc */
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @type {Array<(function (): boolean)|string>}
|
||||
*/
|
||||
validations = [
|
||||
'required',
|
||||
'pattern',
|
||||
|
||||
Reference in New Issue
Block a user