mirror of
https://github.com/FJurmanovic/wallet-web.git
synced 2026-02-06 14:18:08 +00:00
added form validators
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { AppMainElement } from 'components/';
|
||||
|
||||
export default function findMethod(actionString: string, appMain: AppMainElement): Function {
|
||||
if (actionString) {
|
||||
if (actionString && appMain) {
|
||||
const methodSep = actionString.lastIndexOf('#');
|
||||
const tag = actionString.slice(0, methodSep);
|
||||
const method = actionString.slice(methodSep + 1);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
export * from './library';
|
||||
export * from './templating';
|
||||
|
||||
export { default as toKebabCase } from './toKebabCase';
|
||||
export { default as update } from './update-deco';
|
||||
export { default as index } from './index-deco';
|
||||
@@ -7,3 +10,4 @@ export { default as firstUpper } from './first-upper';
|
||||
export { default as query } from './query-deco';
|
||||
export { default as querys } from './querys-deco';
|
||||
export { default as findMethod } from './find-method';
|
||||
export { default as validator } from './validator';
|
||||
|
||||
3
src/core/utils/library.ts
Normal file
3
src/core/utils/library.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { attr, controller, target, targets} from '@github/catalyst';
|
||||
|
||||
export { attr, controller, target, targets }
|
||||
3
src/core/utils/templating.ts
Normal file
3
src/core/utils/templating.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { render, html, TemplateResult } from 'lit-html';
|
||||
|
||||
export { render, html, TemplateResult };
|
||||
25
src/core/utils/validator.ts
Normal file
25
src/core/utils/validator.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import isEmail from 'validator/lib/isEmail';
|
||||
import isDate from 'validator/lib/isDate';
|
||||
import isNumeric from 'validator/lib/isNumeric';
|
||||
import matches from 'validator/lib/matches';
|
||||
|
||||
const validator = {
|
||||
is_email: [isEmail, '{- name} needs to be email format.'],
|
||||
is_date: isDate,
|
||||
is_numeric: isNumeric,
|
||||
matches: matches,
|
||||
is_same: [isSame, '{- name} needs to be same to {- field}.'],
|
||||
required: [required, '{- name} is required.'],
|
||||
};
|
||||
|
||||
function required(str: string): boolean {
|
||||
if (!str || str == '') return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function isSame(str: string, field: string): boolean {
|
||||
if (str === field) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
export default validator;
|
||||
Reference in New Issue
Block a user