Skip to content

Commit 7e5e3ff

Browse files
authored
fix(form): add prompt while still animating
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.
1 parent da0c44e commit 7e5e3ff

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/definitions/behaviors/form.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@
911911
$field = module.get.field(identifier),
912912
$fieldGroup = $field.closest($group),
913913
$prompt = $fieldGroup.children(selector.prompt),
914-
promptExists = $prompt.length > 0
914+
promptExists = $prompt.length > 0,
915+
canTransition = settings.transition && module.can.useElement('transition')
915916
;
916917
module.verbose('Adding field error state', identifier);
917918
if (!internal) {
@@ -920,8 +921,22 @@
920921
;
921922
}
922923
if (settings.inline) {
924+
if (promptExists) {
925+
if (canTransition) {
926+
if ($prompt.transition('is animating')) {
927+
$prompt.transition('stop all');
928+
}
929+
} else if ($prompt.is(':animated')) {
930+
$prompt.stop(true, true);
931+
}
932+
$prompt = $fieldGroup.children(selector.prompt);
933+
promptExists = $prompt.length > 0;
934+
}
923935
if (!promptExists) {
924936
$prompt = $('<div/>').addClass(className.label);
937+
if (!canTransition) {
938+
$prompt.css('display', 'none');
939+
}
925940
$prompt
926941
.appendTo($fieldGroup)
927942
;
@@ -930,7 +945,7 @@
930945
.html(settings.templates.prompt(errors))
931946
;
932947
if (!promptExists) {
933-
if (settings.transition && module.can.useElement('transition')) {
948+
if (canTransition) {
934949
module.verbose('Displaying error with css transition', settings.transition);
935950
$prompt.transition(settings.transition + ' in', settings.duration);
936951
} else {
@@ -939,9 +954,9 @@
939954
.fadeIn(settings.duration)
940955
;
941956
}
942-
} else {
943-
module.verbose('Inline errors are disabled, no inline error added', identifier);
944957
}
958+
} else {
959+
module.verbose('Inline errors are disabled, no inline error added', identifier);
945960
}
946961
},
947962
errors: function (errors) {

0 commit comments

Comments
 (0)