Skip to content

Commit 4f1f89f

Browse files
author
edwardxiao
committed
- validationOption.shouldRenderMsgAsHtml
1 parent c30baa0 commit 4f1f89f

19 files changed

+252
-232
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 4.7.0
2+
3+
- Add ```shouldRenderMsgAsHtml``` to components ```validationOption```, in case you need to render html inside your ```messages``` as stated in issue #29

docs/v4-doc.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
|**asyncMsgObj.message** |**Opt**|**Str** |**(Server response) Your AJAX message. For instance, provide it when backend returns 'USERNAME ALREADY EXIST' (For Textbox or Textarea, better reffer to <a href="https://codesandbox.io/s/async-checking-via-customfunc-emqgw">Example of async checking username existence </a>**|**""** |
6868
|**asyncMsgObj.showOnError** |**Opt**|**Bool** |**(Server response) Show AJAX error message or not.**|**true** |
6969
|**asyncMsgObj.showOnSuccess** |**Opt**|**Bool** |**(Server response) Show AJAX success message or not.**|**false** |
70+
|**asyncMsgObj.shouldRenderMsgAsHtml** |**Opt**|**Bool** |**Should render your message by dangerouslySetInnerHTML.**|**false** |
7071

7172

7273
```js
@@ -120,6 +121,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
120121
// locale: 'en-US', //Optional.[String].Default: "en-US". For error message display. Current options are ['zh-CN', 'en-US']; Default is 'en-US'. If your are looking for more options, you can take a look at 'window.REACT_INPUTS_VALIDATION' section, which provides the extensibility for your own locale.
121122
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", //Optional.[String].Default: "" Show your custom error message no matter what(except the message from customFunc) when it has error if it is provied.
122123
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border.", //Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
124+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
123125
// customFunc: res => { //Optional.[Func].Default: none. Custom function. Returns true or err message or { error: true, message: 'message', showOnSuccess: true }
124126
// if (res != 'milk') {
125127
// return 'Description cannot be other things but milk';
@@ -174,6 +176,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
174176
|**asyncMsgObj.message** |**Opt**|**Str** |**(Server response) Your AJAX message. For instance, provide it when backend returns 'USERNAME ALREADY EXIST'**|**""** |
175177
|**asyncMsgObj.showOnError** |**Opt**|**Bool** |**(Server response) Show AJAX error message or not.**|**true** |
176178
|**asyncMsgObj.showOnSuccess** |**Opt**|**Bool** |**(Server response) Show AJAX success message or not.**|**false** |
179+
|**asyncMsgObj.shouldRenderMsgAsHtml** |**Opt**|**Bool** |**Should render your message by dangerouslySetInnerHTML.**|**false** |
177180

178181
```js
179182
import { Radiobox } from 'react-inputs-validation';
@@ -214,6 +217,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
214217
// locale: 'en-US', //Optional.[String].Default: "en-US". For error message display. Current options are ['zh-CN', 'en-US']; Default is 'en-US'. If your are looking for more options, you can take a look at 'window.REACT_INPUTS_VALIDATION' section, which provides the extensibility for your own locale.
215218
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", //Optional.[String].Default: "". Show your custom error message no matter what when it has error if it is provied.
216219
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border." //Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
220+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
217221
}}
218222
// asyncMsgObj={{
219223
// error: false, // Optional.[Bool].Default: false. (Server response) Backend validation result.
@@ -262,6 +266,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
262266
|**asyncMsgObj.message** |**Opt**|**Str** |**(Server response) Your AJAX message. For instance, provide it when backend returns 'USERNAME ALREADY EXIST'**|**""** |
263267
|**asyncMsgObj.showOnError** |**Opt**|**Bool** |**(Server response) Show AJAX error message or not.**|**true** |
264268
|**asyncMsgObj.showOnSuccess** |**Opt**|**Bool** |**(Server response) Show AJAX success message or not.**|**false** |
269+
|**asyncMsgObj.shouldRenderMsgAsHtml** |**Opt**|**Bool** |**Should render your message by dangerouslySetInnerHTML.**|**false** |
265270

266271
```js
267272
import { Checkbox } from 'react-inputs-validation';
@@ -305,6 +310,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
305310
// locale: 'en-US', //Optional.[String].Default: "en-US". For error message display. Current options are ['zh-CN', 'en-US']; Default is 'en-US'. If your are looking for more options, you can take a look of 'window.REACT_INPUTS_VALIDATION' section, which provides the extensibility for your own locale.
306311
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", //Optional.[String].Default: "". Show your custom error message no matter what when it has error if it is provied.
307312
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border." //Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
313+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
308314
}}
309315
// asyncMsgObj={{
310316
// error: false, // Optional.[Bool].Default: false. (Server response) Backend validation result.
@@ -358,6 +364,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
358364
|**asyncMsgObj.message** |**Opt**|**Str** |**(Server response) Your AJAX message. For instance, provide it when backend returns 'USERNAME ALREADY EXIST'**|**""** |
359365
|**asyncMsgObj.showOnError** |**Opt**|**Bool** |**(Server response) Show AJAX error message or not.**|**true** |
360366
|**asyncMsgObj.showOnSuccess** |**Opt**|**Bool** |**(Server response) Show AJAX success message or not.**|**false** |
367+
|**asyncMsgObj.shouldRenderMsgAsHtml** |**Opt**|**Bool** |**Should render your message by dangerouslySetInnerHTML.**|**false** |
361368
362369
```js
363370
import { Select } from 'react-inputs-validation';
@@ -400,6 +407,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
400407
// locale: 'en-US', //Optional.[String].Default: "en-US". For error message display. Current options are ['zh-CN', 'en-US']; Default is 'en-US'. If your are looking for more options, you can take a look at 'window.REACT_INPUTS_VALIDATION' section, which provides the extensibility for your own locale.
401408
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", //Optional.[String].Default: "". Show your custom error message no matter what when it has error if it is provied.
402409
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border." //Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
410+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
403411
}}
404412
// asyncMsgObj={{
405413
// error: false, // Optional.[Bool].Default: false. (Server response) Backend validation result.
@@ -453,6 +461,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
453461
|**asyncMsgObj.message** |**Opt**|**Str** |**(Server response) Your AJAX message. For instance, provide it when backend returns 'USERNAME ALREADY EXIST' (For Textbox or Textarea, better reffer to <a href="https://codesandbox.io/s/async-checking-via-customfunc-emqgw">Example of async checking username existence </a>**|**""** |
454462
|**asyncMsgObj.showOnError** |**Opt**|**Bool** |**(Server response) Show AJAX error message or not.**|**true** |
455463
|**asyncMsgObj.showOnSuccess** |**Opt**|**Bool** |**(Server response) Show AJAX success message or not.**|**false** |
464+
|**asyncMsgObj.shouldRenderMsgAsHtml** |**Opt**|**Bool** |**Should render your message by dangerouslySetInnerHTML.**|**false** |
456465
457466
```js
458467
import { Textarea } from 'react-inputs-validation';
@@ -507,6 +516,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
507516
// regMsg: 'failed in reg.test(${value})', //Optional.[String].Default: "". Custom regex error message.
508517
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", //Optional.[String].Default: "". Show your custom error message no matter what(except the message from customFunc) when it has error if it is provied.
509518
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border.", //Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
519+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
510520
// customFunc: res => { //Optional.[Func].Default: none. Custom function. Returns true or err message or { error: true, message: 'message', showOnSuccess: true }
511521
// if (res != 'banana') {
512522
// return 'Description cannot be other things but banana';
@@ -526,7 +536,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
526536
527537
# <a name="common-issues"></a>Common questions
528538
529-
### <a name="phone-email-validation-example"></a>Q: What's the recommended way to validate a phone or email?
539+
### <a name="phone-email-validation-example"></a>Q: What's the recommended way to validate a phone or email?
530540
531541
**A**: Check the example of phone and email validation
532542
<a href="https://codesandbox.io/s/13qo2rqxjj">codesandbox example</a>
@@ -571,7 +581,7 @@ import 'react-inputs-validation/lib/react-inputs-validation.min.css';
571581
/>
572582
```
573583
574-
### <a name="memoization"></a>Q: What if my variables got cached due to the react memoization?
584+
### <a name="memoization"></a>Q: What if my variables got cached due to the react memoization?
575585
**A**: You can always pass the value you wish to update into ```validationOption```.
576586
for the below example, just put ```balance``` inside ```validationOption``` and it will not be cached.
577587
@@ -616,7 +626,7 @@ const [amount, setAmount] = useState('')
616626
<br/>
617627
618628
619-
### <a name="custom-error-message"></a>Q: Do you support custom locales?
629+
### <a name="custom-error-message"></a>Q: Do you support custom locales?
620630
**A**: Yes, and it could be multiple locales. By providing ```window.REACT_INPUTS_VALIDATION['customErrorMessage']```, you can overwrite the error message.
621631
622632
<a href="https://codesandbox.io/s/q9vqmk4j84">codesandbox example</a>(located in index.html)
@@ -779,5 +789,5 @@ Then in the component...
779789
}}
780790
/>
781791
```
782-
792+
783793
**For more extensibility or customization please reffer to '[validationOption.customFunc](#customFunc)'**

example/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ class Index extends Component {
928928
// };
929929
// }
930930
// },
931+
// msgOnError: '<a href="google.com">google</a>',
932+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
931933
}}
932934
// asyncMsgObj={this.state.nameAsyncMsgObj}
933935
// asyncMsgObj={{
@@ -996,6 +998,8 @@ class Index extends Component {
996998
// locale: 'en-US', // Optional.[String].Default: "en-US". For error message display. Current options are ['zh-CN', 'en-US']; Default is 'en-US'.
997999
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", // Optional.[String].Default: "". Show your custom error message no matter what when it has error if it is provied.
9981000
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border." // Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
1001+
// msgOnError: '<a href="google.com">google</a>',
1002+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
9991003
}}
10001004
// asyncMsgObj={{
10011005
// error: false, // Optional.[Bool].Default: false. (Server response) Backend validation result.
@@ -1063,6 +1067,8 @@ class Index extends Component {
10631067
// locale: 'en-US', // Optional.[String].Default: "en-US". For error message display. Current options are ['zh-CN', 'en-US']; Default is 'en-US'.
10641068
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", // Optional.[String].Default: "". Show your custom error message no matter what when it has error if it is provied.
10651069
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border." // Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
1070+
// msgOnError: '<a href="google.com">google</a>',
1071+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
10661072
}}
10671073
// asyncMsgObj={{
10681074
// error: false, // Optional.[Bool].Default: false. (Server response) Backend validation result.
@@ -1130,6 +1136,8 @@ class Index extends Component {
11301136
// locale: 'en-US', // Optional.[String].Default: "en-US". For error message display. Current options are ['zh-CN', 'en-US']; Default is 'en-US'.
11311137
// msgOnError: "Your custom error message if you provide the validationOption['msgOnError']", // Optional.[String].Default: "". Show your custom error message no matter what when it has error if it is provied.
11321138
// msgOnSuccess: "Your custom success message if you provide the validationOption['msgOnSuccess']. Otherwise, it will not show, not even green border." // Optional.[String].Default: "". Show your custom success message no matter what when it has error if it is provied.
1139+
// msgOnError: '<a href="google.com">google</a>',
1140+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
11331141
}}
11341142
// asyncMsgObj={{
11351143
// error: false, // Optional.[Bool].Default: false. (Server response) Backend validation result.
@@ -1213,6 +1221,8 @@ class Index extends Component {
12131221
// }
12141222
// return true;
12151223
// }
1224+
// msgOnError: '<a href="google.com">google</a>',
1225+
// shouldRenderMsgAsHtml: true, // Optional.[Bool].Default: false. Should render your message by dangerouslySetInnerHTML.
12161226
}}
12171227
// asyncMsgObj={{
12181228
// error: false, // Optional.[Bool].Default: false. (Server response) Backend validation result.

lib/Checkbox.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface DefaultValidationOption {
77
locale?: string;
88
msgOnError?: string;
99
msgOnSuccess?: string;
10+
shouldRenderMsgAsHtml?: boolean;
1011
}
1112
interface DefaultAsyncMsgObj {
1213
error?: boolean;

lib/Radiobox.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface DefaultValidationOption {
77
locale?: string;
88
msgOnError?: string;
99
msgOnSuccess?: string;
10+
shouldRenderMsgAsHtml?: boolean;
1011
}
1112
interface DefaultAsyncMsgObj {
1213
error?: boolean;

lib/Select.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface DefaultValidationOption {
77
locale?: string;
88
msgOnError?: string;
99
msgOnSuccess?: string;
10+
shouldRenderMsgAsHtml?: boolean;
1011
}
1112
export declare const isValidValue: (list: OptionListItem[], value: any) => boolean;
1213
export declare const getItem: (list: OptionListItem[], value: any) => OptionListItem;

lib/Textarea.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface DefaultValidationOption {
1414
msgOnError?: string;
1515
msgOnSuccess?: string;
1616
customFunc?: Function | undefined;
17+
shouldRenderMsgAsHtml?: boolean;
1718
}
1819
interface DefaultAsyncMsgObj {
1920
error?: boolean;

lib/Textbox.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface DefaultValidationOption {
1717
msgOnError?: string;
1818
msgOnSuccess?: string;
1919
customFunc?: Function | undefined;
20+
shouldRenderMsgAsHtml?: boolean;
2021
}
2122
interface AttributesInputObj {
2223
id?: string;

lib/components/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-inputs-validation.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)