Skip to content

Commit a94932d

Browse files
authored
fix: Some accessibility issues (#8)
* fix: Add required attribute to checkbox & value box * fix: Don't create iframe for every form by default
1 parent f826f3d commit a94932d

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

gwtbootstrap3/src/main/java/org/gwtbootstrap3/client/ui/CheckBox.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
import org.gwtbootstrap3.client.ui.base.HasFormValue;
24+
import org.gwtbootstrap3.client.ui.base.HasRequired;
2425
import org.gwtbootstrap3.client.ui.constants.Styles;
2526
import org.gwtbootstrap3.client.ui.gwt.ButtonBase;
2627
import org.gwtbootstrap3.client.ui.gwt.FormPanel;
@@ -68,7 +69,7 @@
6869
* </p>
6970
*/
7071
public class CheckBox extends ButtonBase implements HasName, HasValue<Boolean>, HasWordWrap, HasDirectionalSafeHtml,
71-
HasDirectionEstimator, IsEditor<LeafValueEditor<Boolean>>, HasFormValue, HasChangeHandlers {
72+
HasDirectionEstimator, IsEditor<LeafValueEditor<Boolean>>, HasFormValue, HasChangeHandlers, HasRequired {
7273

7374
protected final SpanElement labelElem = Document.get().createSpanElement();
7475
protected final InputElement inputElem;
@@ -502,4 +503,17 @@ protected void onUnload() {
502503
setValue(getValue());
503504
}
504505

506+
@Override
507+
public void setRequired(boolean required) {
508+
if (required) {
509+
inputElem.setAttribute(HasRequired.REQUIRED, HasRequired.REQUIRED);
510+
} else {
511+
inputElem.removeAttribute(HasRequired.REQUIRED);
512+
}
513+
}
514+
515+
@Override
516+
public boolean getRequired() {
517+
return inputElem.hasAttribute(HasRequired.REQUIRED);
518+
}
505519
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.gwtbootstrap3.client.ui.base;
2+
3+
/*
4+
* #%L
5+
* GwtBootstrap3
6+
* %%
7+
* Copyright (C) 2013 GwtBootstrap3
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
/**
24+
* @author Pontus Enmark
25+
*/
26+
public interface HasRequired {
27+
String REQUIRED = "required";
28+
29+
void setRequired(boolean required);
30+
31+
boolean getRequired();
32+
}

gwtbootstrap3/src/main/java/org/gwtbootstrap3/client/ui/base/ValueBoxBase.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import com.google.web.bindery.event.shared.HandlerRegistration;
4545

4646
public class ValueBoxBase<T> extends com.google.gwt.user.client.ui.ValueBoxBase<T> implements HasId, HasReadOnly,
47-
HasResponsiveness, HasPlaceholder, HasAutoComplete, HasSize<InputSize>, HasEditorErrors<T>,
47+
HasResponsiveness, HasPlaceholder, HasAutoComplete, HasRequired, HasSize<InputSize>, HasEditorErrors<T>,
4848
HasErrorHandler, HasValidators<T>, HasBlankValidator<T> {
4949

5050
private static final String MAX_LENGTH = "maxlength";
@@ -214,4 +214,17 @@ public HandlerRegistration addValidationChangedHandler(ValidationChangedHandler
214214
return validatorMixin.addValidationChangedHandler(handler);
215215
}
216216

217+
@Override
218+
public void setRequired(boolean required) {
219+
if (required) {
220+
getElement().setAttribute(HasRequired.REQUIRED, HasRequired.REQUIRED);
221+
} else {
222+
getElement().removeAttribute(HasRequired.REQUIRED);
223+
}
224+
}
225+
226+
@Override
227+
public boolean getRequired() {
228+
return getElement().hasAttribute(HasRequired.REQUIRED);
229+
}
217230
}

gwtbootstrap3/src/main/java/org/gwtbootstrap3/client/ui/base/form/AbstractForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ interface IFrameTemplate extends SafeHtmlTemplates {
227227
private Element synthesizedFrame;
228228

229229
public AbstractForm() {
230-
this(true);
230+
this(false);
231231
}
232232

233233
public AbstractForm(boolean createIFrame) {

0 commit comments

Comments
 (0)