File: //home/arjun/projects/buyercall/buyercall/assets/components/forms/sectionInvalidator.js
export function wire($form, $section, msg = 'The form has been updated. Please, save it first.') {
let wasChanged = false;
$form.find('input').on('change.secinvalid', function(e) {
var $flashMsgContainer = $('#flash-messages');
var $alertContainer = $('#flash-messages .invalidate.alert');
if (!$flashMsgContainer[0]) {
$section.before('<div id="flash-messages">'+
'<div class="invalidate alert alert-warning" role="alert">'+
msg +
'</div>'+
'</div>');
} else if(!$alertContainer[0]) {
$flashMsgContainer.append('<div class="invalidate alert alert-warning" role="alert">'+
msg +
'</div>')
} else {
$alertContainer.html(msg);
}
if(wasChanged) return;
$section.find(':button, a')
.prop('disabled', true)
.addClass('disabled')
.attr('title', 'The form has been updated. Please, save it first.')
wasChanged = true;
})
}
export function unwire($form, $section) {
$form.find('input').off('change.secinvalid');
var $flashMsgContainer = $('#flash-messages');
var $alertContainer = $('#flash-messages .invalidate.alert');
$alertContainer.remove();
if ($flashMsgContainer.find('>div').length == 0) $flashMsgContainer.remove();
$section.find(':button, a')
.prop('disabled', false)
.removeClass('disabled')
.attr('title', '');
}