Skip to content

Commit

Permalink
fix(form): add prompt while still animating
Browse files Browse the repository at this point in the history
If a manual add prompt is triggered while the form is submitting / ends validation and possibly existing prompts get faded out via transition, then the new prompt is not shown as it is still found in the dom, but not recognized that the prompt will vanish from the dom once the transition has ended.

I also fixed fadein without transition module as the fadeIn did not work at all.
  • Loading branch information
lubber-de authored May 24, 2023
1 parent da0c44e commit 7e5e3ff
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@
$field = module.get.field(identifier),
$fieldGroup = $field.closest($group),
$prompt = $fieldGroup.children(selector.prompt),
promptExists = $prompt.length > 0
promptExists = $prompt.length > 0,
canTransition = settings.transition && module.can.useElement('transition')
;
module.verbose('Adding field error state', identifier);
if (!internal) {
Expand All @@ -920,8 +921,22 @@
;
}
if (settings.inline) {
if (promptExists) {
if (canTransition) {
if ($prompt.transition('is animating')) {
$prompt.transition('stop all');
}
} else if ($prompt.is(':animated')) {
$prompt.stop(true, true);
}
$prompt = $fieldGroup.children(selector.prompt);
promptExists = $prompt.length > 0;
}
if (!promptExists) {
$prompt = $('<div/>').addClass(className.label);
if (!canTransition) {
$prompt.css('display', 'none');
}
$prompt
.appendTo($fieldGroup)
;
Expand All @@ -930,7 +945,7 @@
.html(settings.templates.prompt(errors))
;
if (!promptExists) {
if (settings.transition && module.can.useElement('transition')) {
if (canTransition) {
module.verbose('Displaying error with css transition', settings.transition);
$prompt.transition(settings.transition + ' in', settings.duration);
} else {
Expand All @@ -939,9 +954,9 @@
.fadeIn(settings.duration)
;
}
} else {
module.verbose('Inline errors are disabled, no inline error added', identifier);
}
} else {
module.verbose('Inline errors are disabled, no inline error added', identifier);
}
},
errors: function (errors) {
Expand Down

0 comments on commit 7e5e3ff

Please sign in to comment.