Skip to content

Instantly share code, notes, and snippets.

@AjayKumar01
Last active October 3, 2016 20:32
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 AjayKumar01/5d7e7b62a9230034a155b2c19d633aa5 to your computer and use it in GitHub Desktop.
Save AjayKumar01/5d7e7b62a9230034a155b2c19d633aa5 to your computer and use it in GitHub Desktop.
Duplicate primary Email validation in record.js
({
extendsFrom: 'RecordView',
initialize: function(options) {
this._super('initialize', [options]);
this.model.addValidationTask('check_email', _.bind(this._doValidateEmail, this));
},
_doValidateEmail: function(fields, errors, callback) {
console.log("test function");
_.each(this.model.get('email'), function(emailObject) {
if (emailObject.primary_address) { //check if primary
var primaryEmail = emailObject.email_address;
//do more things with the primary email
var emailAddress = primaryEmail;
var data = {
results: [],
},
options = {},
callbacks = {},
url;
// add the search term to the URL params
options.q = emailAddress;
// the first 10 results should be enough
//we can use 2 or 5 any number which is very less.
options.max_num = 10;
// build the URL for fetching recipients that match the search term
url = app.api.buildURL('Mail', 'recipients/find', null, options);
// create the callbacks
callbacks.success = function(result) {
var email_count = result.records.length; //Assigning the count of returned email addresses.
console.log(email_count);
if (email_count > 0) {
errors['email'] = errors['email'] || {};
errors['email'].required = true;
}
callback(null, fields, errors);
};
callbacks.error = function() {
console.log("api error");
};
app.api.call('read', url, null, callbacks);
}
});
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment