Attach validation to new dom elements

pull/279/head
Halil İbrahim Kalkan 7 years ago
parent b711520f4f
commit 632d4434bb

@ -1,4 +1,4 @@
(function() {
(function($) {
abp.dom.onNodeAdded(function (args) {
args.$el.findWithSelf('[data-toggle="tooltip"]').tooltip({
@ -8,6 +8,13 @@
args.$el.findWithSelf('[data-toggle="popover"]').popover({
container: 'body'
});
var $forms = args.$el.findWithSelf('form');
if ($forms.length) {
$forms.each(function() {
$.validator.unobtrusive.parse($(this));
});
}
});
abp.dom.onNodeRemoved(function (args) {
@ -26,4 +33,4 @@
});
});
})();
})(jQuery);

@ -66,11 +66,8 @@ $.validator.defaults.ignore = ''; //TODO: Would be better if we can apply only f
_$modal = _$modalContainer.find('.modal');
_$form = _$modalContainer.find('form');
if (_$form.length) {
$.validator.unobtrusive.parse(_$form); //TODO: We should do a more common system to initialize component on ajax-loaded DOM elements. validator.unobtrusive.parse is only one thing to do.
if (_$form.attr('data-ajaxForm') !== 'false') {
//TODO: Create abpAjaxForm to not repeat that code!
_$form.abpAjaxForm({
dataType: 'json',
success: function() {
_publicApi.setResult.apply(_publicApi, arguments);
_$modal.modal('hide');

@ -9,14 +9,17 @@
var options = $.extend({}, $.fn.abpAjaxForm.defaults, userOptions);
options.beforeSubmit = function (arr, $form) {
var retVal = userOptions.beforeSubmit && userOptions.beforeSubmit.apply(this, arguments);
if (userOptions.beforeSubmit && userOptions.beforeSubmit.apply(this, arguments) === false) {
return false;
}
if (retVal !== false) {
$form.find("button[type='submit']").buttonBusy(true);
//TODO: Disable other buttons..?
if (!$form.valid()) {
return false;
}
return retVal;
$form.find("button[type='submit']").buttonBusy(true);
//TODO: Disable other buttons..?
return true;
};
options.error = function (jqXhr) {

Loading…
Cancel
Save