Skip to content

Commit

Permalink
Provide screen reader alerts for resource form.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimisgold committed Oct 29, 2024
1 parent f671b33 commit 0c26543
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 19 additions & 2 deletions admin/themes/default/javascripts/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ Omeka.Elements = {};
});
fieldDiv.html(response);
fieldDiv.trigger('omeka:elementformload');
}
fieldDiv.find('.add-element').focus();
setTimeout(() => {
Omeka.Elements.alertElementChange('element-' + elementId, fieldDiv);
}, 2000);
}
});
};

Omeka.Elements.alertElementChange = function (elementId, fieldDiv) {
var alertsDiv = $('#' + elementId + '-alerts');
var rowCount = fieldDiv.find('.input-block').length;
alertsDiv.find('span.count').text(rowCount);
}

/**
* Set up add/remove element buttons for ElementText inputs.
*
Expand Down Expand Up @@ -93,14 +103,16 @@ Omeka.Elements = {};
context.find(addSelector).click(function (event) {
event.preventDefault();
var fieldDiv = $(this).parents(fieldSelector);

Omeka.Elements.elementFormRequest(fieldDiv, {add: '1'}, elementFormPartialUrl, recordType, recordId);
});

// When a remove button is clicked, remove that input from the form.
context.find(removeSelector).click(function (event) {
event.preventDefault();
var removeButton = $(this);
var fieldDiv = $(this).parents(fieldSelector);
var elementId = fieldDiv.attr('id');

// Don't delete the last input block for an element.
if (removeButton.parents(fieldSelector).find(inputBlockSelector).length === 1) {
Expand All @@ -117,6 +129,11 @@ Omeka.Elements = {};
});
inputBlock.remove();

fieldDiv.find('textarea').last().focus();
setTimeout(() => {
Omeka.Elements.alertElementChange(elementId, fieldDiv);
}, 2000);

// Hide remove buttons for fields with one input.
$(fieldSelector).each(function () {
var removeButtons = $(this).find(removeSelector);
Expand Down
5 changes: 4 additions & 1 deletion application/views/helpers/ElementForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public function elementForm(Element $element, Omeka_Record_AbstractRecord $recor
}

// Compose html for element form
$html = $divWrap ? '<div class="field" id="element-' . html_escape($element->id) . '" aria-live="polite">' : '';
$html = '<div id="element-' . $element->id . '-alerts" class="sr-only alerts" aria-atomic="true" aria-live="polite">';
$html .= __('Number of rows in "%s":', $components['label']) . '<span class="count">1</span>';
$html .= '</div>';
$html .= $divWrap ? '<div class="field" id="element-' . html_escape($element->id) . '">' : '';

$html .= '<div class="field-meta two columns alpha">';
$html .= $components['label'];
Expand Down

0 comments on commit 0c26543

Please sign in to comment.