added form validators

This commit is contained in:
Fran Jurmanović
2021-06-12 11:54:13 +02:00
parent 130246ca88
commit d2fe244e04
38 changed files with 424 additions and 267 deletions

View File

@@ -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);

View File

@@ -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';

View File

@@ -0,0 +1,3 @@
import { attr, controller, target, targets} from '@github/catalyst';
export { attr, controller, target, targets }

View File

@@ -0,0 +1,3 @@
import { render, html, TemplateResult } from 'lit-html';
export { render, html, TemplateResult };

View 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;