Skip to content

Instantly share code, notes, and snippets.

@andxbes
Created February 22, 2024 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andxbes/6b8feb3291851e3d648960a695fe3675 to your computer and use it in GitHub Desktop.
Save andxbes/6b8feb3291851e3d648960a695fe3675 to your computer and use it in GitHub Desktop.
Ninja forms validate email
// On Document Ready...
jQuery(document).ready(function ($) {
if (typeof Marionette !== 'undefined') {
var myCustomFieldController = Marionette.Object.extend({
initialize: function () {
var submitChannel = Backbone.Radio.channel('submit');
this.listenTo(submitChannel, 'validate:field', this.validateRequired);
var fieldsChannel = Backbone.Radio.channel('fields');
this.listenTo(fieldsChannel, 'change:modelValue', this.validateRequired);
},
validateRequired: function (model) {
if (model.get('type') === 'email') {
let value = model.get('value');
if (value.indexOf("@gmail.com") !== -1) {
Backbone.Radio.channel('fields').request('add:error', model.get('id'), 'email-domain-validate-field-error', 'Sorry, but at the moment we do not support the use of email addresses from the "gmail.com" domain. Please choose another mail service.');
} else {
Backbone.Radio.channel('fields').request('remove:error', model.get('id'), 'email-domain-validate-field-error');
}
} else {
return;
}
}
});
new myCustomFieldController();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment