Skip to content

Commit 59db183

Browse files
authored
feat(form): optional support all field errors in inline prompt
According to the (unclear) docs there are two possibilities to show errors in an inline prompt label. You can supply either a string or an array of strings. However, this was always ignored. It always uses only the very first field error, regardless how many other errors may exists. The error message instead (when not using inline errors) is always showing all possible rule errors by default. This PR now also shows all errors of a field in an inline prompt label just like the error message already does. That said, the existing prompt template now, more logical, is used to created the label content (just like the error template does for non inline errors), rather than the label node itself (this is now done automatically). Even if this is a breaking change, i doubt the prompt label was ever customised by somebody , because of the overriding logic (which made the prompt template useless.) The previous behavior totally ignored the prompt templates inner content, because right after that, the html content inside the label was immediatly overridden all the time. (see comments below)
1 parent d5d7bab commit 59db183

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/definitions/behaviors/form.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -887,13 +887,13 @@ $.fn.form = function(parameters) {
887887
}
888888
if(settings.inline) {
889889
if(!promptExists) {
890-
$prompt = settings.templates.prompt(errors, className.label);
890+
$prompt = $('<div/>').addClass(className.label);
891891
$prompt
892892
.appendTo($fieldGroup)
893893
;
894894
}
895895
$prompt
896-
.html(errors[0])
896+
.html(settings.templates.prompt(errors))
897897
;
898898
if(!promptExists) {
899899
if(settings.transition && module.can.useElement('transition') && $module.transition('is supported')) {
@@ -1638,15 +1638,22 @@ $.fn.form.settings = {
16381638
html += '<li>' + value + '</li>';
16391639
});
16401640
html += '</ul>';
1641-
return $(html);
1641+
return html;
16421642
},
16431643

1644-
// template that produces label
1645-
prompt: function(errors, labelClasses) {
1646-
return $('<div/>')
1647-
.addClass(labelClasses)
1648-
.html(errors[0])
1644+
// template that produces label content
1645+
prompt: function(errors) {
1646+
if(errors.length === 1){
1647+
return errors[0];
1648+
}
1649+
var
1650+
html = '<ul class="ui list">'
16491651
;
1652+
$.each(errors, function(index, value) {
1653+
html += '<li>' + value + '</li>';
1654+
});
1655+
html += '</ul>';
1656+
return html;
16501657
}
16511658
},
16521659

src/definitions/collections/form.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@
325325
background: @promptBackground !important;
326326
border: @promptBorder !important;
327327
color: @promptTextColor !important;
328+
& li:before {
329+
color: @promptTextColor;
330+
}
328331
}
329332
& when (@variationFormInline) {
330333
.ui.form .inline.fields .field .prompt,

0 commit comments

Comments
 (0)