@egodesign/form 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +59 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @egodesign/form
2
- A lightweight Javascript component to fully validate and send forms.
2
+ A Javascript class to fully validate and send forms.
3
3
  </br></br>
4
4
 
5
5
  ## Usage:
@@ -11,6 +11,41 @@ const myForm = new EgoForm({
11
11
  element: document.getElementById('myForm'),
12
12
  submitType: 'fetch',
13
13
  debug: true,
14
+ submitDataFormat: 'formData',
15
+ requestHeaders: {},
16
+ fieldGroups: {
17
+ phone_numbers: [
18
+ 'phone',
19
+ 'mobile'
20
+ ]
21
+ },
22
+ serializerIgnoreList: ['ignore'],
23
+ classes: {
24
+ requiredField: '--required',
25
+ requiredIfFilledField: '--required-if-filled',
26
+ fieldHasError: '--has-error',
27
+ controlHasError: 'is-danger',
28
+ hiddenErrorMessage: 'is-hidden',
29
+ formSubmittingState: '--submitting',
30
+ buttonSubmittingState: 'is-loading'
31
+ },
32
+ customValidations: {
33
+ test: [{
34
+ name: 'isValid',
35
+ condition: (value) => value === 'testing',
36
+ message: 'This field value should be "testing".'
37
+ }]
38
+ },
39
+ customValidationsMessages: {
40
+ "fieldName": {
41
+ "empty": "message",
42
+ "invalid": "message",
43
+ }
44
+ },
45
+ onStepChange: (previous, next) => console.log(current, next),
46
+ onValidationError: fields => console.log(fields),
47
+ onSubmitStart: () => console.log('Submit start'),
48
+ onSubmitEnd: () => console.log('Submit end'),
14
49
  onSuccess: resp => console.log('Success', resp),
15
50
  onError: err => console.log('Error', err)
16
51
  });
@@ -101,6 +136,7 @@ const myForm = new EgoForm({
101
136
  | *fieldGroups* | Group fields as nestes objects inside the body of the request. Should recieve an object containing key-value pairs, where the key is the name of the group and the value an array listing the field names. | Object or `null`.
102
137
  | *classes* | Customize some classes to match your own. Should recieve an object containig the replaced classnames. See [customizable classes] | Object or `null`.
103
138
  | *customValidations* | Define your own validations. Should recieve an object containig key-value pairs, where the key is the name of the custom `data-type`, and the value an array of validations defining a condition to be passed and a message in case it's not. | Object or `null`.
139
+ | *customValidationMessages* | Lets you customize existing validation messages. It expects an object containing the name of the field and the custom messages inside. Refer to [Usage](#usage) to see an example. | Object or `null`.
104
140
  | *resetOnSuccess* | This option completely resets the form and its fields. | Boolean, default `true`.
105
141
  | *scrollOnError* | This option smoothly scrolls the page to show the first field with errors. Useful when building long forms to make sure the user sees the errors. | Boolean, default `true`.
106
142
  | *debug* | On debug mode, the form won't be submitted. Intead, every step will be logged into the dev console of the browser. | Boolean, default `false`.
@@ -109,6 +145,8 @@ const myForm = new EgoForm({
109
145
  ### Events
110
146
  | Name | Description | Accepted values |
111
147
  | --- | ----------- | ----------- |
148
+ | *onStepChange* | Event triggered every time there's a step change. Only available for stepped forms. It returns the previous and the next steps. | An anonymous function or `null`.
149
+ | *onValidationError* | Event triggered when there's any validation error. It returns an array containing the names of the invalid fields. | An anonymous function or `null`.
112
150
  | *onSubmitStart* | Event triggered when the submit starts. | An anonymous function or `null`.
113
151
  | *onSubmitEnd* | Event triggered when the submit ends, regardless of the outcome. | An anonymous function or `null`.
114
152
  | *onSuccess* | Event triggered when the request results successful. | An anonymous function or `null`.
@@ -117,11 +155,25 @@ const myForm = new EgoForm({
117
155
 
118
156
  ### Validation:
119
157
  In order to use validations, you must set the correct data type for each field. You can do so by adding a `type` data attribute to the field element, e.g; `<div class="form__field" data-type="text">`. This attribute will be used by the validator to run certain tests. Here's a list of the different available data types:
120
- | Name | Description | Extra attributes |
158
+ | Name | Description |
159
+ | ---| --- |
160
+ | `text` | This can be considered as the default type. It's use for simple text input and it doesn't have any special validation appart from the required ones. |
161
+ | `email` | Used for email inputs. It validates the value to comply the requirement for a well formed email address. |
162
+ | `url` | Used for URL inputs. It validates the value to comply the requirement for a well formed URL. |
163
+ | `cuit` / `cuil` | It validates the value to comply the requirement for a valid CUIT or CUIL number, applying the official formula. |
164
+ | `password_repeat` | Use this type alogn with a password field whit an ID of `password`, to validate that both fields have the same value. Mostly intended for password reset forms. |
165
+ | `single_checkbox` | This type validates that a specific checkbox is checked. Useful for cases like terms and conditions acceptance. |
166
+
167
+ ### Masks:
168
+ Add this class names to the field element in oprder to apply some masks and filters to your inputs.
169
+
170
+ | Class name | Description | Extra attributes |
121
171
  | ---| --- | ----------- |
122
- | `text` | This can be considered as the default type. It's use for simple text input and it doesn't have any special validation appart from the required ones. | |
123
- | `email` | Used for email inputs. It validates the value to comply the requirement for a well formed email address. | |
124
- | `url` | Used for URL inputs. It validates the value to comply the requirement for a well formed URL. | |
125
- | `cuit`/`cuil` | It validates the value to comply the requirement for a valid CUIT or CUIL number, applying the official formula. | |
126
- | `money` | It validates the value to comply the requirement for a valid CUIT or CUIL number, applying the official formula. | |
172
+ | `--number` | It converts the value to only numbers, with the option of being formated and support decimals. | `data-thousands-separator`: if declared it will be used to separate thousands.<br />`data-decimal-separator`: if declared it will be used to separate decimals.<br />`data-decimals`: the number of decimal places, defaults to 2. |
173
+ | `--money-amount` | It converts the input into a valid currency expression. | `data-currency`: this attribute is use to mask the field value adding the currency at the begining. Defualts to '$'. |
174
+ | `--phone` | It filters the value using a (opinionated) regular expression, which only allows numbers, plus symbols, hyphens, parentheses and white spaces. | |
175
+ <br />
127
176
 
177
+ ## Extras
178
+ ### Toggle password visibility
179
+ Add a button with the class name `form__toggle-password-visibility` inside the field element to toggle the control (input) type between `password` and `text`. Note: the control and the button must be siblings.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egodesign/form",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "JS Form component",
5
5
  "module": "dist/js/egodesign.form.esm.min.js",
6
6
  "browser": "dist/js/egodesign.form.umd.min.js",