1.4.10 • Published 10 months ago
@uzum-tech/account-form v1.4.10
Table of Contents
Installing
Package manager
Using npm:
npm i @uzum-tech/account-form
Using yarn:
yarn add @uzum-tech/account-form
CDN
Using jsDelivr
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@uzum-tech/account-form/lib/style.css">
<script src="https://cdn.jsdelivr.net/npm/@uzum-tech/account-form/lib/main.iife.js"></script>
Using unpkg
<link rel="stylesheet" href="https://unpkg.com/@uzum-tech/account-form/lib/style.css">
<script src="https://unpkg.com/@uzum-tech/account-form/lib/main.iife.js"></script>
Usage
Initialization
Default value source: 1
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<div data-account-form data-source="-1" style="width: 530px"></div>
</body>
</html>
Script
import '@uzum-tech/account-form/lib/style.css';
import AccountForm from '@uzum-tech/account-form';
new AccountForm('[data-account-form]');
Add/Remove listeners
import AccountForm, { AccountFormEvent, AccountApplication } from '@uzum-tech/account-form';
const accountForm = new AccountForm();
const handleAccountFormSubmit = (payload: AccountApplication) => console.log(payload);
// Add listener
accountForm.addListener(
AccountFormEvent.SUBMIT,
handleAccountFormSubmit
);
// Remove listener
accountForm.removeListener(
AccountFormEvent.SUBMIT,
handleAccountFormSubmit
);
// Remove all listener
accountForm.removeAllListeners(
AccountFormEvent.SUBMIT,
handleAccountFormSubmit
);
Events from AccountFormEvent
:
Value | Payload | Description |
---|---|---|
SUBMIT | AccountApplication | Will fire after successful validation, before sending the request |
ERROR_RESPONSE | AccountApplication | Will fire after an unsuccessful response |
SUCCESS_RESPONSE | AccountApplication | Will fire after a successful response |
FINALLY_RESPONSE | AccountApplication | It will always work after the response |
VALIDATE | AccountApplicationFormValidationResult | It will work after the form is validated, before sending the request. Validation status is available in the event payload |
BLUR | AccountApplicationFieldBlurResult | Will fire after removing focus from any field inside the form |
TOGGLE_TIN_OR_PINFL | boolean | Will fire after toggle 'Не помню ИНН или ПИНФЛ' checkbox |
TOGGLE_ACCEPT_CHECKBOX | boolean | Will fire after toggle 'Я соглашаюсь на обработку персональных данных' checkbox |
Fields visibility
import AccountForm from '@uzum-tech/account-form';
const accountForm = new AccountForm();
// Show/hide single field
accountForm.showFields('name');
accountForm.hideFields('name');
// Show/hide multiple fields
accountForm.showFields('name', 'phone');
accountForm.hideFields('name', 'phone');
Default values
import AccountForm, { AccountProduct } from '@uzum-tech/account-form';
const accountForm = new AccountForm();
accountForm.setDefaultFields({
product: AccountProduct.ACCOUNT_IN_SOUMS
});
Custom request sending
- If you return a non-empty string, it will be displayed as error text.
- If nothing is returned, the response will be considered successful
import AccountForm, { AccountApplication } from '@uzum-tech/account-form';
const accountForm = new AccountForm();
accountForm.onRequest = (payload: AccountApplication) => {
// Logic for sending the request
};
Toggle pinfl
- updates the mask
- updates localization
- if necessary, trims the original field value
- emits the event
TOGGLE_ACCEPT_CHECKBOX
import AccountForm from '@uzum-tech/account-form';
const accountForm = new AccountForm();
// To support both INN and PINFL
accountForm.withPinfl();
// To leave only the INN
accountForm.withoutPinfl();
API Version
- by default version is 2.0
- version will send in header
X-Api-Version
import { ApiVersion } from '@uzum-tech/account-form';
const accountForm = new AccountForm();
// Change version
accountForm.apiVersion = ApiVersion.v3; // Available keys - v1-v4
// Clear version in order to remove X-Api-Version header
accountForm.apiVersion = undefined;
Custom response callback
- If you want to handle the response you can pass the function
import AccountForm from '@uzum-tech/account-form';
const accountForm = new AccountForm();
accountForm.onResponse = (response: ApiResponse<ELMAResponse>): void => {
// Logic for handling the response
};
Update text for send button
- If you want to update text of send button, you can use method
setSendButtonLocale
- The method accepts
text
as a text, that should be replaced - BE CAREFULL: After changing text, there will be no 'reactive' locale on button. That means that changing language will not force any changing in text.
import AccountForm from '@uzum-tech/account-form';
const accountForm = new AccountForm();
accountForm.setSendButtonLocale('Book a call');
Computed values
Property | Type | Readonly |
---|---|---|
acceptChecked | boolean | Yes |
hideTINOrPINFLChecked | boolean | Yes |
lang | string | No |
productValue | AccountProduct | null | No |
buttonLoading | boolean | No |
Status alerts
import AccountForm from '@uzum-tech/account-form';
const accountForm = new AccountForm();
// If you don't need to show alert then change the value to false
accountForm.autoShowAlert = false;
Manual submitting
import AccountForm from '@uzum-tech/account-form';
const accountForm = new AccountForm();
// If you need submit with validations and all other handlers
accountForm.submit();
// If you need request only without handlers
accountForm.requestOnly();
Reset
import AccountForm from '@uzum-tech/account-form';
const accountForm = new AccountForm();
// If you need disable auto reset after submit
accountForm.autoReset = false;
// If you need reset manually
accountForm.resetForm();
License
1.4.6
10 months ago
1.4.5
10 months ago
1.4.4
10 months ago
1.4.3
10 months ago
1.4.2
10 months ago
1.4.1
10 months ago
1.4.0
10 months ago
1.3.0
10 months ago
1.4.9
10 months ago
1.4.8
10 months ago
1.4.10
10 months ago
1.4.7
10 months ago
1.2.3
11 months ago
1.2.2
11 months ago
1.2.1
11 months ago
1.2.0
11 months ago
1.1.7
1 year ago
1.1.6
1 year ago
1.1.5
1 year ago
1.1.4
1 year ago
1.1.3
1 year ago
1.1.2
1 year ago
1.1.1
1 year ago
1.0.1
1 year ago
1.0.0
2 years ago
0.3.8
2 years ago
0.3.7
2 years ago
0.3.6
2 years ago
0.3.5
2 years ago
0.3.4
2 years ago
0.3.3
2 years ago
0.3.2
2 years ago
0.3.1
2 years ago
0.3.0
2 years ago
0.2.14
2 years ago
0.2.13
2 years ago
0.2.12
2 years ago
0.2.11
2 years ago
0.2.10
2 years ago
0.2.9
2 years ago
0.2.8
2 years ago
0.2.7
2 years ago
0.2.6
2 years ago
0.2.5
2 years ago
0.2.4
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.0
2 years ago