*/
CRM.utils.initialValueChanged = function(el) {
var isDirty = false;
- $(':input:visible, :input.select2-offscreen', el).each(function () {
+ $(':input:visible, .select2-container:visible+:input.select2-offscreen', el).not('[type=submit], [type=button], .crm-action-menu').each(function () {
var initialValue = $(this).data('crm-initial-value');
// skip change of value for submit buttons
- if (initialValue !== undefined && !$(this).hasClass('form-submit') && initialValue != $(this).val()) {
+ if (initialValue !== undefined && !_.isEqual(initialValue, $(this).val())) {
isDirty = true;
}
});
}
})
.on('submit', function(e) {
- // CRM-14353 - disable changes warn when submitting the form
- $('[data-warn-changes]').removeAttr('data-warn-changes');
+ // CRM-14353 - disable changes warn when submitting a form
+ $('[data-warn-changes]').attr('data-warn-changes', 'false');
})
- ;
-
- window.onbeforeunload = function() {
- if (CRM.utils.initialValueChanged($('form[data-warn-changes=true]'))) {
- return ts('You have unsaved changes.');
- }
- };
+ ;
+
+ // CRM-14353 - Warn of unsaved changes for forms which have opted in
+ window.onbeforeunload = function() {
+ if (CRM.utils.initialValueChanged($('form[data-warn-changes=true]:visible'))) {
+ return ts('You have unsaved changes.');
+ }
+ };
/**
* Function to make multiselect boxes behave as fields in small screens