Skip to content

Commit

Permalink
JQMText and JQMTextArea - keyboard TAB navigation prevented in case o…
Browse files Browse the repository at this point in the history
…f disabled widget.
  • Loading branch information
slavap committed Aug 7, 2018
1 parent c3b5426 commit d529069
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 10 deletions.
Expand Up @@ -63,6 +63,7 @@
import com.sksamuel.jqm4gwt.form.elements.JQMSlider;
import com.sksamuel.jqm4gwt.form.elements.JQMTelephone;
import com.sksamuel.jqm4gwt.form.elements.JQMText;
import com.sksamuel.jqm4gwt.form.elements.JQMTextArea;
import com.sksamuel.jqm4gwt.form.elements.JQMUrl;
import com.sksamuel.jqm4gwt.html.Heading;
import com.sksamuel.jqm4gwt.html.Paragraph;
Expand Down Expand Up @@ -543,6 +544,10 @@ interface UiBinder extends com.google.gwt.uibinder.client.UiBinder<JQMPage, Test
@UiField JQMColumnToggle colToggle1;
@UiField JQMButton colClassNamesBtn;

@UiField JQMText textDisabled;
@UiField JQMTextArea textAreaDisabled;
@UiField JQMButton switchTextDisabledBtn;


public TestView1() {
page.addPageHandler(new JQMPageEvent.DefaultHandler() {
Expand Down Expand Up @@ -1158,6 +1163,12 @@ void colClassNamesBtnClick(ClickEvent e) {
colToggle1.setColClassNames("1=CENTER, 2=RIGHT_BODY CENTER_HEAD abc, 3=CENTER");
}

@UiHandler("switchTextDisabledBtn")
void switchTextDisabledBtnClick(ClickEvent e) {
textDisabled.setEnabled(!textDisabled.isEnabled());
textAreaDisabled.setEnabled(!textAreaDisabled.isEnabled());
}

{
form.setSubmissionHandler(new SubmissionHandler<JQMForm>() {
@Override
Expand Down
Expand Up @@ -244,6 +244,10 @@
<b:JQMButton builtInIcon="PLUS" ui:field="enableTextButton" text="Enable Text" inline="true" mini="true" />

<e:JQMText ui:field="textReadOnly" text="Text (readonly)" value="qwerty uiopa" readOnly="true" />

<e:JQMText ui:field="textDisabled" text="Text (disabled)" value="qwerty uiopa" enabled="false" />
<e:JQMTextArea ui:field="textAreaDisabled" text="Text area (disabled)" value="qwerty uiopa" enabled="false" />
<b:JQMButton ui:field="switchTextDisabledBtn" text="Switch Text Disabled/Enabled" inline="true" mini="true" />

<!-- TODO fix col/rows setter <e:JQMTextArea text="textAreaText" columns="40" rows="20"/>-->
<e:JQMTextArea text="textAreaText"/>
Expand Down
Expand Up @@ -74,6 +74,8 @@ public class JQMText extends JQMFieldContainer implements HasText<JQMText>, HasV

private static final String JQM4GWT_READONLY = "jqm4gwt-readonly";

private Integer savedTabIndex = null;

/**
* Create a new {@link JQMText} element with no label
*/
Expand Down Expand Up @@ -251,11 +253,6 @@ public void setPreventFocusZoom(boolean b) {
setAttribute("data-prevent-focus-zoom", String.valueOf(b));
}

@Override
public void setTabIndex(int index) {
input.setTabIndex(index);
}

/**
* Set the text of the label to the given @param text
*/
Expand Down Expand Up @@ -383,4 +380,50 @@ public JQMText withCorners(boolean corners) {
setCorners(corners);
return this;
}

@Override
protected void onLoad() {
super.onLoad();
if (!isEnabled()) {
Element inputElt = getInputElt();
if (savedTabIndex == null) savedTabIndex = inputElt.getTabIndex();
inputElt.setTabIndex(-1);
}
}

@Override
public void setEnabled(boolean value) {
boolean prevEnabled = isEnabled();
super.setEnabled(value);
if (prevEnabled == value) return;

if (isAttached()) {
Element inputElt = getInputElt();
if (value) {
if (savedTabIndex != null) {
inputElt.setTabIndex(savedTabIndex);
savedTabIndex = null;
}
} else {
savedTabIndex = inputElt.getTabIndex();
inputElt.setTabIndex(-1);
}
}
}

@Override
public void setTabIndex(int value) {
if (isAttached()) {
if (isEnabled()) {
getInputElt().setTabIndex(value);
savedTabIndex = null;
} else {
savedTabIndex = value;
}
} else {
input.setTabIndex(value);
JQMCommon.setAttribute(getInputElt(), "tabindex", String.valueOf(value));
}
}

}
@@ -1,6 +1,7 @@
package com.sksamuel.jqm4gwt.form.elements;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
Expand Down Expand Up @@ -54,6 +55,8 @@ public class JQMTextArea extends JQMFieldContainer implements HasGridDimensions<
private final FormLabel label = new FormLabel();
private final TextArea input = new TextArea();

private Integer savedTabIndex = null;

/**
* Create a new {@link JQMTextArea} with no label text
*/
Expand Down Expand Up @@ -151,11 +154,6 @@ public void setFocus(boolean focused) {
input.setFocus(focused);
}

@Override
public void setTabIndex(int index) {
input.setTabIndex(index);
}

@Override
public void setText(String text) {
label.setText(text);
Expand Down Expand Up @@ -303,4 +301,63 @@ public JQMTextArea withCorners(boolean corners) {
setCorners(corners);
return this;
}

public Element getInputElt() {
return input.getElement();
}

public String getInputId() {
return input.getElement().getId();
}

public void setInputId(String id) {
input.getElement().setId(id);
input.setName(id);
label.setFor(id);
}

@Override
protected void onLoad() {
super.onLoad();
if (!isEnabled()) {
Element inputElt = getInputElt();
if (savedTabIndex == null) savedTabIndex = inputElt.getTabIndex();
inputElt.setTabIndex(-1);
}
}

@Override
public void setEnabled(boolean value) {
boolean prevEnabled = isEnabled();
super.setEnabled(value);
if (prevEnabled == value) return;

if (isAttached()) {
Element inputElt = getInputElt();
if (value) {
if (savedTabIndex != null) {
inputElt.setTabIndex(savedTabIndex);
savedTabIndex = null;
}
} else {
savedTabIndex = inputElt.getTabIndex();
inputElt.setTabIndex(-1);
}
}
}

@Override
public void setTabIndex(int value) {
if (isAttached()) {
if (isEnabled()) {
getInputElt().setTabIndex(value);
savedTabIndex = null;
} else {
savedTabIndex = value;
}
} else {
input.setTabIndex(value);
JQMCommon.setAttribute(getInputElt(), "tabindex", String.valueOf(value));
}
}
}

0 comments on commit d529069

Please sign in to comment.