misc: remove fixed fields from top errors summary (#82633)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-04-21 16:21:19 +02:00
parent 7106fbcecf
commit 703ff210ae
2 changed files with 22 additions and 3 deletions

View File

@ -118,7 +118,7 @@ class FormDefForm(Form):
if hasattr(widget, 'field') and widget.has_error() and not getattr(widget, 'is_hidden', False):
widget_with_errors.append(widget)
if widget_with_errors:
t += htmltext('<p>')
t += htmltext('<p id="field-error-links">')
t += str(
ngettext(
'The following field has an error:',
@ -128,9 +128,13 @@ class FormDefForm(Form):
)
t += ' '
for i, widget in enumerate(widget_with_errors):
t += htmltext('<a href="#form_label_%s">%s</a>') % (widget.get_name_for_id(), widget.title)
t += htmltext('<a data-field-name="%s" href="#form_label_%s">%s</a>') % (
widget.get_name_for_id(),
widget.get_name_for_id(),
widget.title,
)
if i < len(widget_with_errors) - 1:
t += str(_(', '))
t += htmltext('<span class="list-comma">%s</span>') % _(', ')
t += htmltext('</p>')
return t.getvalue()

View File

@ -1048,6 +1048,21 @@ const LiveValidation = (function(){
field.setAttribute("aria-describedby", this.errorEl.id)
this.widget.classList.remove(this.errorClass)
this.hasError = false
var base_field_widget_id = null
var current_widget = this.widget
// for fields in blocks, a single error is displayed on top, using the block name,
// look for it and remove it as soon as the user is correcting the form
// (even if there are still some errors in other subfields)
while (current_widget.nodeName != 'FORM') {
if (current_widget.dataset.widgetNameForId) base_field_widget_id = current_widget.dataset.widgetNameForId
current_widget = current_widget.parentNode
}
var comma = document.querySelector(`#field-error-links [data-field-name="${base_field_widget_id}"] + span.list-comma`)
if (comma) comma.remove()
document.querySelector(`#field-error-links [data-field-name="${base_field_widget_id}"]`).remove()
if (! document.querySelector('#field-error-links a')) {
document.querySelector('#field-error-links').remove()
}
}
init() {