Commit 62533285 by Jonathan Piacenti

Make alternative fields required for accessibility.

parent a27f413b
...@@ -270,6 +270,11 @@ ...@@ -270,6 +270,11 @@
opacity: 0.7; opacity: 0.7;
} }
.xblock--drag-and-drop--editor .tab .field-error {
outline: none;
box-shadow: 0 0 10px darkred;
}
.xblock--drag-and-drop--editor .icon.add:before { .xblock--drag-and-drop--editor .icon.add:before {
content: ''; content: '';
height: 10px; height: 10px;
......
...@@ -59,15 +59,45 @@ function DragAndDropEditBlock(runtime, element, params) { ...@@ -59,15 +59,45 @@ function DragAndDropEditBlock(runtime, element, params) {
_fn.build.clickHandlers(); _fn.build.clickHandlers();
}, },
validate: function() {
var fields = $element.find('.tab').not('.hidden').find('input, textarea');
var success = true;
fields.each(function(index, field) {
field = $(field);
// Right now our only check is if a field is set or not.
field.removeClass('field-error');
if (! field[0].checkValidity()) {
field.addClass('field-error');
success = false;
}
});
if (! success) {
runtime.notify('error', {
'title': window.gettext("There was an error with your form."),
'message': window.gettext("Please check over your submission.")
});
}
return success
},
clickHandlers: function() { clickHandlers: function() {
var $fbkTab = _fn.build.$el.feedback.tab, var $fbkTab = _fn.build.$el.feedback.tab,
$zoneTab = _fn.build.$el.zones.tab, $zoneTab = _fn.build.$el.zones.tab,
$itemTab = _fn.build.$el.items.tab; $itemTab = _fn.build.$el.items.tab;
$element.one('click', '.continue-button', function(e) { var self = this;
$element.one('click', '.continue-button', function loadSecondTab(e) {
// $fbkTab -> $zoneTab // $fbkTab -> $zoneTab
e.preventDefault(); e.preventDefault();
if (!self.validate()) {
$(e.target).one('click', loadSecondTab);
return
}
_fn.build.form.feedback(_fn.build.$el.feedback.form); _fn.build.form.feedback(_fn.build.$el.feedback.form);
for (var i = 0; i < _fn.data.zones.length; i++) { for (var i = 0; i < _fn.data.zones.length; i++) {
_fn.build.form.zone.add(_fn.data.zones[i]); _fn.build.form.zone.add(_fn.data.zones[i]);
...@@ -94,10 +124,15 @@ function DragAndDropEditBlock(runtime, element, params) { ...@@ -94,10 +124,15 @@ function DragAndDropEditBlock(runtime, element, params) {
$fbkTab.addClass('hidden'); $fbkTab.addClass('hidden');
$zoneTab.removeClass('hidden'); $zoneTab.removeClass('hidden');
$(this).one('click', function(e) { $(this).one('click', function loadThirdTab(e) {
// $zoneTab -> $itemTab // $zoneTab -> $itemTab
e.preventDefault(); e.preventDefault();
if (!self.validate()) {
$(e.target).one('click', loadThirdTab);
return
}
for (var i = 0; i < _fn.data.items.length; i++) { for (var i = 0; i < _fn.data.items.length; i++) {
_fn.build.form.item.add(_fn.data.items[i]); _fn.build.form.item.add(_fn.data.items[i]);
} }
...@@ -111,10 +146,14 @@ function DragAndDropEditBlock(runtime, element, params) { ...@@ -111,10 +146,14 @@ function DragAndDropEditBlock(runtime, element, params) {
$(this).addClass('hidden'); $(this).addClass('hidden');
$('.save-button', element).parent() $('.save-button', element).parent()
.removeClass('hidden') .removeClass('hidden')
.one('click', function(e) { .one('click', function submitForm(e) {
// $itemTab -> submit // $itemTab -> submit
e.preventDefault(); e.preventDefault();
if (!self.validate()) {
$(e.target).one('click', submitForm);
return
}
_fn.build.form.submit(); _fn.build.form.submit();
}); });
}); });
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
type="text" type="text"
placeholder="{% trans 'For example, http://example.com/background.png or /static/background.png' %}"> placeholder="{% trans 'For example, http://example.com/background.png or /static/background.png' %}">
<label class="h3" for="background-description">{% trans "Background description" %}</label> <label class="h3" for="background-description">{% trans "Background description" %}</label>
<textarea id="background-description" <textarea required id="background-description"
aria-describedby="background-description-description"></textarea> aria-describedby="background-description-description"></textarea>
<div id="background-description-description" class="target-image-form-help"> <div id="background-description-description" class="target-image-form-help">
{% blocktrans %} {% blocktrans %}
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
<input type="text" <input type="text"
id="zone-{{index}}-title" id="zone-{{index}}-title"
class="title" class="title"
value="{{ title }}" /> value="{{ title }}"
required />
<a href="#" class="remove-zone hidden"> <a href="#" class="remove-zone hidden">
<div class="icon remove"></div> <div class="icon remove"></div>
</a> </a>
...@@ -24,7 +25,8 @@ ...@@ -24,7 +25,8 @@
id="zone-{{index}}-description" id="zone-{{index}}-description"
class="description" class="description"
value="{{ description }}" value="{{ description }}"
placeholder="{{i18n 'Describe this zone to non-visual users'}}" /> placeholder="{{i18n 'Describe this zone to non-visual users'}}"
required />
<div class="layout"> <div class="layout">
<label for="zone-{{index}}-width">{{i18n "width"}}</label> <label for="zone-{{index}}-width">{{i18n "width"}}</label>
<input type="text" <input type="text"
...@@ -79,7 +81,7 @@ ...@@ -79,7 +81,7 @@
</div> </div>
<div class="row"> <div class="row">
<label for="item-{{id}}-image-description">{{i18n "Image description (should provide sufficient information to place the item even if the image did not load)"}}</label> <label for="item-{{id}}-image-description">{{i18n "Image description (should provide sufficient information to place the item even if the image did not load)"}}</label>
<textarea id="item-{{id}}-image-description" <textarea required id="item-{{id}}-image-description"
class="item-image-description">{{ imageDescription }}</textarea> class="item-image-description">{{ imageDescription }}</textarea>
</div> </div>
<div class="row"> <div class="row">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment