Commit 6f616e13 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 1183398: Mandatory custom fields block form submission if they are hidden and have no value

r=gerv a=dkl
parent a2ae1545
...@@ -506,7 +506,8 @@ function handleVisControllerValueChange(e, args) { ...@@ -506,7 +506,8 @@ function handleVisControllerValueChange(e, args) {
var controller = args[1]; var controller = args[1];
var values = args[2]; var values = args[2];
var label_container = var field = document.getElementById(controlled_id);
var label_container =
document.getElementById('field_label_' + controlled_id); document.getElementById('field_label_' + controlled_id);
var field_container = var field_container =
document.getElementById('field_container_' + controlled_id); document.getElementById('field_container_' + controlled_id);
...@@ -521,10 +522,20 @@ function handleVisControllerValueChange(e, args) { ...@@ -521,10 +522,20 @@ function handleVisControllerValueChange(e, args) {
if (selected) { if (selected) {
YAHOO.util.Dom.removeClass(label_container, 'bz_hidden_field'); YAHOO.util.Dom.removeClass(label_container, 'bz_hidden_field');
YAHOO.util.Dom.removeClass(field_container, 'bz_hidden_field'); YAHOO.util.Dom.removeClass(field_container, 'bz_hidden_field');
// Restore the 'required' attribute for mandatory fields.
if (field.getAttribute('data-required') == "true") {
field.setAttribute('required', 'true');
field.setAttribute('aria-required', 'true');
}
} }
else { else {
YAHOO.util.Dom.addClass(label_container, 'bz_hidden_field'); YAHOO.util.Dom.addClass(label_container, 'bz_hidden_field');
YAHOO.util.Dom.addClass(field_container, 'bz_hidden_field'); YAHOO.util.Dom.addClass(field_container, 'bz_hidden_field');
// A hidden field must never be required, because the user cannot set it.
if (field.getAttribute('data-required') == "true") {
field.removeAttribute('required');
field.removeAttribute('aria-required');
}
} }
} }
......
...@@ -43,13 +43,17 @@ ...@@ -43,13 +43,17 @@
value="[% value FILTER html %]" size="40" value="[% value FILTER html %]" size="40"
maxlength="[% constants.MAX_FREETEXT_LENGTH FILTER none %]" maxlength="[% constants.MAX_FREETEXT_LENGTH FILTER none %]"
[% IF field.type == constants.FIELD_TYPE_INTEGER %] pattern="\d+[% IF dontchange %]|[% dontchange FILTER html %][% END %]" [% END %] [% IF field.type == constants.FIELD_TYPE_INTEGER %] pattern="\d+[% IF dontchange %]|[% dontchange FILTER html %][% END %]" [% END %]
[% ' aria-required="true" required' IF field.is_mandatory %]> [% IF field.is_mandatory %]
data-required="true" [% 'aria-required="true" required' UNLESS field_hidden %]
[% END %]>
[% CASE [constants.FIELD_TYPE_DATETIME, constants.FIELD_TYPE_DATE] %] [% CASE [constants.FIELD_TYPE_DATETIME, constants.FIELD_TYPE_DATE] %]
[% size = (field.type == constants.FIELD_TYPE_DATE) ? 10 : 20 %] [% size = (field.type == constants.FIELD_TYPE_DATE) ? 10 : 20 %]
<input name="[% field.name FILTER html %]" size="[% size FILTER none %]" <input name="[% field.name FILTER html %]" size="[% size FILTER none %]"
id="[% field.name FILTER html %]" id="[% field.name FILTER html %]"
value="[% value FILTER html %]" value="[% value FILTER html %]"
[% ' aria-required="true" required' IF field.is_mandatory %] [% IF field.is_mandatory %]
data-required="true" [% 'aria-required="true" required' UNLESS field_hidden %]
[% END %]
onchange="updateCalendarFromField(this)"> onchange="updateCalendarFromField(this)">
<button type="button" class="calendar_button" <button type="button" class="calendar_button"
id="button_calendar_[% field.name FILTER html %]" id="button_calendar_[% field.name FILTER html %]"
...@@ -67,8 +71,9 @@ ...@@ -67,8 +71,9 @@
<span id="[% field.name FILTER html %]_input_area"> <span id="[% field.name FILTER html %]_input_area">
<input name="[% field.name FILTER html %]" id="[% field.name FILTER html %]" <input name="[% field.name FILTER html %]" id="[% field.name FILTER html %]"
value="[% value FILTER html %]" size="7" value="[% value FILTER html %]" size="7"
[% ' aria-required="true" required' IF field.is_mandatory %]> [% IF field.is_mandatory %]
data-required="true" [% 'aria-required="true" required' UNLESS field_hidden %]
[% END %]>
</span> </span>
[% IF value %] [% IF value %]
...@@ -90,14 +95,15 @@ ...@@ -90,14 +95,15 @@
<select id="[% field.name FILTER html %]" <select id="[% field.name FILTER html %]"
name="[% field.name FILTER html %]" name="[% field.name FILTER html %]"
[% IF field.type == constants.FIELD_TYPE_MULTI_SELECT %] [% IF field.type == constants.FIELD_TYPE_MULTI_SELECT %]
[% SET field_size = 5 %] [% SET field_size = 5 %]
[% IF field.legal_values.size < 5 %] [% IF field.legal_values.size < 5 %]
[% SET field_size = field.legal_values.size %] [% SET field_size = field.legal_values.size %]
[% END %] [% END %]
size="[% field_size FILTER html %]" multiple="multiple" size="[% field_size FILTER html %]" multiple="multiple"
[% ' aria-required="true" required' IF field.is_mandatory %] [% IF field.is_mandatory %]
[% END %] data-required="true" [% 'aria-required="true" required' UNLESS field_hidden %]
> [% END %]
[% END %]>
[% IF allow_dont_change %] [% IF allow_dont_change %]
<option value="[% dontchange FILTER html %]" <option value="[% dontchange FILTER html %]"
[% ' selected="selected"' IF value == dontchange %]> [% ' selected="selected"' IF value == dontchange %]>
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# defaultcontent: (optional) Default content for the textarea. # defaultcontent: (optional) Default content for the textarea.
# mandatory: (optional) Boolean specifying whether or not the textarea # mandatory: (optional) Boolean specifying whether or not the textarea
# is mandatory. # is mandatory.
# field_hidden: (optional) True if the field is hidden. Only useful if
# the field is mandatory.
#%] #%]
<textarea [% IF name %]name="[% name FILTER html %]"[% END %] <textarea [% IF name %]name="[% name FILTER html %]"[% END %]
...@@ -46,7 +48,7 @@ ...@@ -46,7 +48,7 @@
onFocus="this.rows=[% maxrows FILTER html %]" onFocus="this.rows=[% maxrows FILTER html %]"
[% END %] [% END %]
[% IF mandatory %] [% IF mandatory %]
aria-required="true" required data-required="true" [% 'aria-required="true" required' UNLESS field_hidden %]
[% END %] [% END %]
[% IF onchange %] [% IF onchange %]
onchange="[% onchange FILTER html %]" onchange="[% onchange FILTER html %]"
......
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