Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [#2] Add licenseplate and iban component #18

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/formio/components/iban.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {InputComponentSchema, MultipleCapable} from '..';

type Validator = 'required';
type TranslatableKeys = 'label' | 'description' | 'tooltip';

export type IbanInputSchema = InputComponentSchema<string, Validator, TranslatableKeys>;

/**
* @group Form.io components
* @category Base types
*/
export interface BaseIbanComponentSchema extends Omit<IbanInputSchema, 'hideLabel' | 'disabled'> {
type: 'iban';
validateOn: 'blur';
}

/**
* @group Form.io components
* @category Concrete types
*/
export type IbanComponentSchema = MultipleCapable<BaseIbanComponentSchema>;
2 changes: 2 additions & 0 deletions src/formio/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export * from './datetime';
export * from './time';
export * from './phonenumber';
export * from './postcode';
export * from './iban';
export * from './licenseplate';
export * from './number';
export * from './file';

Expand Down
34 changes: 34 additions & 0 deletions src/formio/components/licenseplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {InputComponentSchema, MultipleCapable} from '..';

type Validator = 'required' | 'pattern';
type TranslatableKeys = 'label' | 'description' | 'tooltip';

export type LicensePlateInputSchema = InputComponentSchema<string, Validator, TranslatableKeys>;

/**
* @group Form.io components
* @category Base types
*/
export interface LicensePlateProperties {
type: 'licenseplate';
validate: {
pattern: '^[a-zA-Z0-9]{1,3}\\-[a-zA-Z0-9]{1,3}\\-[a-zA-Z0-9]{1,3}$';
};
validateOn: 'blur';
}

/**
* @group Form.io components
* @category Base types
*/
export type BaseLicensePlateComponentSchema = Omit<
LicensePlateInputSchema,
'hideLabel' | 'placeholder'
> &
LicensePlateProperties;

/**
* @group Form.io components
* @category Concrete types
*/
export type LicensePlateComponentSchema = MultipleCapable<BaseLicensePlateComponentSchema>;
5 changes: 5 additions & 0 deletions src/formio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
DateTimeComponentSchema,
EmailComponentSchema,
FileComponentSchema,
IbanComponentSchema,
LicensePlateComponentSchema,
NumberComponentSchema,
PhoneNumberComponentSchema,
PostcodeComponentSchema,
Expand Down Expand Up @@ -45,6 +47,9 @@ export type AnyComponentSchema =
| PostcodeComponentSchema
| FileComponentSchema
| NumberComponentSchema
// special types
| IbanComponentSchema
| LicensePlateComponentSchema
// layout
| ContentComponentSchema;

Expand Down
129 changes: 129 additions & 0 deletions test-d/formio/components/iban.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import {expectAssignable, expectNotAssignable} from 'tsd';

import {IbanComponentSchema} from '../../../lib';

// minimal textfield component schema
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'blur',
});


// multiple false and appropriate default value type
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'blur',
multiple: false,
defaultValue: '',
});

// multiple true and appropriate default value type
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'blur',
multiple: true,
defaultValue: [''],
});

// full, correct schema
expectAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
// basic tab
label: 'Some IBAN',
key: 'someIban',
description: '',
tooltip: 'A tooltip',
showInSummary: true,
showInEmail: false,
showInPDF: true,
multiple: false,
hidden: false,
clearOnHide: true,
isSensitiveData: true,
defaultValue: '',
// Advanced tab
conditional: {
show: undefined,
when: '',
eq: '',
},
// Validation tab
validate: {
required: false,
plugins: [],
},
translatedErrors: {nl: {required: 'Geef IBAN.'}},
errors: {required: 'Geef email.'},
// registration tab
registration: {
attribute: '',
},
// translations tab in builder form
openForms: {
translations: {
nl: {label: 'foo'},
},
},
// fixed but not editable
validateOn: 'blur',
});

// validateOn not `blur`
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'change',
});

// missing validateOn
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
});

// invalid, multiple true and non-array default value
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'blur',
multiple: true,
defaultValue: '',
});

// invalid, multiple false and array default value
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'blur',
multiple: false,
defaultValue: [''],
});

// invalid, multiple true and wrong default value in array element
expectNotAssignable<IbanComponentSchema>({
id: 'yejak',
type: 'iban',
key: 'someIban',
label: 'Some IBAN',
validateOn: 'blur',
multiple: true,
defaultValue: [0],
});
Loading