Add validation for email restrictions

[MAILPOET-4890]
This commit is contained in:
Jan Lysý
2023-02-13 09:57:04 +01:00
committed by Aschepikov
parent ac9eddc239
commit 45d4af878b
2 changed files with 12 additions and 1 deletions

View File

@ -75,7 +75,9 @@ class UsageRestriction extends Component<Props, State> {
componentDidMount() { componentDidMount() {
const $inputs = jQuery( const $inputs = jQuery(
'.mailpoet_field_coupon_minimum_amount input, .mailpoet_field_coupon_maximum_amount input', '.mailpoet_field_coupon_minimum_amount input,' +
'.mailpoet_field_coupon_maximum_amount input,' +
'.mailpoet_field_coupon_email_restrictions input',
); );
if ($inputs.length) { if ($inputs.length) {
$inputs.each((_index, input) => { $inputs.each((_index, input) => {
@ -113,6 +115,7 @@ class UsageRestriction extends Component<Props, State> {
<PanelBody <PanelBody
title={MailPoet.I18n.t('usageRestriction')} title={MailPoet.I18n.t('usageRestriction')}
className="mailpoet-coupon-block-usage-restriction" className="mailpoet-coupon-block-usage-restriction"
initialOpen={false}
> >
<PanelRow> <PanelRow>
<TextControl <TextControl
@ -246,6 +249,13 @@ class UsageRestriction extends Component<Props, State> {
this.setValueCallback('emailRestrictions', emailRestrictions); this.setValueCallback('emailRestrictions', emailRestrictions);
this.setState({ emailRestrictions }); this.setState({ emailRestrictions });
}} }}
type="text"
pattern="^[-\w+.%\*]+@[\w-.\*]+\.[A-Za-z\*]{2,4}(?:,[-\w+.%\*]+@[\w-.\*]+\.[A-Za-z\*]{2,4})*$"
data-parsley-validate
data-parsley-trigger="input"
data-parsley-error-message={MailPoet.I18n.t(
'emailRestrictionsFieldsErrorMessage',
)}
/> />
</PanelRow> </PanelRow>
</PanelBody> </PanelBody>

View File

@ -464,6 +464,7 @@
'noCategories': __('No categories'), 'noCategories': __('No categories'),
'allowedEmails': __('Allowed emails'), 'allowedEmails': __('Allowed emails'),
'noRestrictions': __('No restrictions'), 'noRestrictions': __('No restrictions'),
'emailRestrictionsFieldsErrorMessage': __('Separate email addresses with commas. You can also use an asterisk (*) to match parts of an email. For example "*@gmail.com" would match all gmail addresses.'),
}) %> }) %>
<% endblock %> <% endblock %>