Skip to content
Snippets Groups Projects
Commit d06277fb authored by Frode Petterson's avatar Frode Petterson
Browse files

JI-1318 Add IDs for list widgets as well

(very useful for text editors)
parent 33e5ee9a
Branches
No related tags found
No related merge requests found
......@@ -13,6 +13,8 @@ H5PEditor.ListEditor = (function ($) {
var entity = list.getEntity();
// Create list html
var $list = $('<ul/>', {
id: list.getId(),
'aria-describedby': list.getDescriptionId(),
'class': 'h5p-ul'
});
......
......@@ -23,6 +23,9 @@ H5PEditor.SemanticStructure = (function ($) {
// Support old editor libraries
self.field = {};
const id = H5PEditor.getNextFieldId(field);
const descriptionId = (field.description !== undefined ? H5PEditor.getDescriptionId(id) : undefined)
/**
* Global instance variables.
* @private
......@@ -48,13 +51,14 @@ H5PEditor.SemanticStructure = (function ($) {
// Create field label
if (field.label !== 0) {
// Add label
createLabel(self.label, field.optional).appendTo($wrapper);
createLabel(self.label, field.optional, id).appendTo($wrapper);
}
// Create description
var $description;
if (field.description !== undefined) {
$description = $('<div/>', {
'id': descriptionId,
'class': 'h5peditor-field-description',
text: field.description,
appendTo: $wrapper
......@@ -247,6 +251,24 @@ H5PEditor.SemanticStructure = (function ($) {
return field.name;
};
/**
* Get the input id the label points to.
*
* @returns {String} Name of the current field
*/
self.getId = function () {
return id;
};
/**
* Get the description id to point to.
*
* @returns {String} Name of the current field
*/
self.getDescriptionId = function () {
return descriptionId;
};
// Must be last
init();
}
......@@ -262,8 +284,9 @@ H5PEditor.SemanticStructure = (function ($) {
* @param {String} text
* @returns {jQuery}
*/
var createLabel = function (text, optional) {
var createLabel = function (text, optional, id) {
return $('<label/>', {
'for': id,
'class': 'h5peditor-label' + (optional ? '' : ' h5peditor-required'),
text: text
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment