");
},
//Default http error handling, note this function only applies to http errors not form processor errors, for that please override "handleErrors"
handleHttpErrors: function (jqXHR, textStatus, errorThrown) {
if (this.settings.region in submissionFailedErrors) {
this.$formErrorMessages.show().text(submissionFailedErrors[this.settings.region]);
} else {
this.$formErrorMessages.show().text(submissionFailedErrors['en_us']);
}
},
//Default error handling, note this function only applies to form processor errors, NOT http errors, for that please override "handleHttpErrors"
handleErrors: function (response) {
var formID = response.formID
var fields = response.data;
var errors = [];
for (var field in fields) {
if (fields.hasOwnProperty(field)) {
var datum = fields[field];
if (datum.status != 'SUCCESS') {
errors.push({name: datum.name, value: datum.value, errors: datum.messages});
}
}
}
//Find and show outstanding errors
$.each(errors, function (index, error) {
if (error.errors.join) {
$('#' + formID + ' .fp-field-error-' + error.name).show().html(error.errors.join('
'));
}
$('#' + formID + ' .fp-field-error-' + error.name).closest('.fp-container').addClass('fp-container--error');
});
//Show any form level errors that we might have
if (response.messages.length > 0) {
this.$formErrorMessages.show().html(response.messages.join('
'));
}
}
});
//Wire up the jquery plugin
$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
});
};
})(jQuery, window, document);
(function ($, window, document, undefined) {
"use strict";
var pluginName = "addFormProcessorErrorElements",
defaults = {};
function Plugin(element, options) {
this.element = element;
this.$formElement = $(element);
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
var that = this;
that.addMainFormError();
that.addFieldErrors();
}, addMainFormError: function () {
this.$formElement.find('#fieldList').before('
');
}, addFieldErrors: function () {
var that = this;
this.$formElement.find('input[type=text], select, input[type=hidden], textarea').each(function () {
var $this = $(this);
var name = $(this).attr('name').replace("[]", "");
$this.after('
');
});
this.$formElement.find('input[type=checkbox]').each(function () {
var $this = $(this);
var name = $(this).attr('name').replace("[]", "");
var id = $(this).attr('id');
$this.next('label').after('
');
});
}
});
//Wire up the jquery plugin
$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
});
};
})(jQuery, window, document);
jQuery(document).ready(function ($) {
var $form = $('.fp').addFormProcessorErrorElements().formProcessor({
handleSuccess: function (data) {
/*console.log(data);
console.log(data.formID);
if (data.formID == "FP_20180209_Design_And_Visualization_News") {
console.log("Test2");
$('.fp').replaceWith("
" + data.messages.join(". ") + "
")
try {
dtm_track('formSubmit', {formID: 'FP_20180209_Design_And_Visualization_News'});
} catch (e) {
}
}*/
},
handleHttpErrors: function (jqXHR, textStatus, errorThrown) {
console.log(this.$formErrorMessages);
this.$formErrorMessages.show().text(textStatus);
this.$formfieldErrorMessages.show().text(textStatus);
}
});
});