Created
February 22, 2024 09:33
-
-
Save andxbes/6b8feb3291851e3d648960a695fe3675 to your computer and use it in GitHub Desktop.
Ninja forms validate email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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