diff options
author | Artur Signell <artur@vaadin.com> | 2013-06-18 22:59:01 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-06-26 10:50:56 +0300 |
commit | 06357c0a910db38af3b7d7c371aebd38cd70844b (patch) | |
tree | 70a48952e983d882d2833af7125deaead13baa34 | |
parent | a0b4d992e2f7d7a662d1b8aeb098bc40238090d6 (diff) | |
download | vaadin-framework-06357c0a910db38af3b7d7c371aebd38cd70844b.tar.gz vaadin-framework-06357c0a910db38af3b7d7c371aebd38cd70844b.zip |
Ensure caption is used when child is set to required (#12077)
Change-Id: Id4a9674c1b2e1c41dbba1f6fde11502400591a52
3 files changed, 207 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/VCaption.java b/client/src/com/vaadin/client/VCaption.java index d033c2b4fe..d0338de4a1 100644 --- a/client/src/com/vaadin/client/VCaption.java +++ b/client/src/com/vaadin/client/VCaption.java @@ -437,6 +437,12 @@ public class VCaption extends HTML { return true; } + if (state instanceof AbstractFieldState) { + if (((AbstractFieldState) state).required) { + return true; + } + } + return false; } diff --git a/uitest/src/com/vaadin/tests/components/abstractfield/RequiredIndicatorForFieldsWithoutCaption.html b/uitest/src/com/vaadin/tests/components/abstractfield/RequiredIndicatorForFieldsWithoutCaption.html new file mode 100644 index 0000000000..bc013f42ef --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/abstractfield/RequiredIndicatorForFieldsWithoutCaption.html @@ -0,0 +1,109 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="http://localhost:8888/" /> +<title>New Test</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">New Test</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.abstractfield.RequiredIndicatorForFieldsWithoutCaption?debug&restartApplication</td> + <td></td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VGridLayout[0]/domChild[2]/domChild[0]/domChild[0]</td> + <td>v-required-field-indicator</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>//div[3]/div/div[2]/div/div/span</td> + <td>v-required-field-indicator</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>//div[4]/div/div[2]/div/div/span</td> + <td>v-required-field-indicator</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VAbsoluteLayout[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]</td> + <td>v-required-field-indicator</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VCssLayout[0]/domChild[1]/domChild[0]</td> + <td>v-required-field-indicator</td> +</tr> +<!--Set to not required--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]</td> + <td>9,4</td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VGridLayout[0]/domChild[2]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>//div[3]/div/div[2]/div/div/span</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>//div[4]/div/div[2]/div/div/span</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VAbsoluteLayout[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VCssLayout[0]/domChild[1]/domChild[0]</td> + <td></td> +</tr> +<!--Set to required again--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]</td> + <td>9,4</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VGridLayout[0]/domChild[2]/domChild[0]/domChild[0]</td> + <td>v-required-field-indicator</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>//div[3]/div/div[2]/div/div/span</td> + <td>v-required-field-indicator</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>//div[4]/div/div[2]/div/div/span</td> + <td>v-required-field-indicator</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VAbsoluteLayout[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]</td> + <td>v-required-field-indicator</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>vaadin=runcomvaadintestscomponentsabstractfieldRequiredIndicatorForFieldsWithoutCaption::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VCssLayout[0]/domChild[1]/domChild[0]</td> + <td>v-required-field-indicator</td> +</tr> + +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/components/abstractfield/RequiredIndicatorForFieldsWithoutCaption.java b/uitest/src/com/vaadin/tests/components/abstractfield/RequiredIndicatorForFieldsWithoutCaption.java new file mode 100644 index 0000000000..56e593ce0f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/abstractfield/RequiredIndicatorForFieldsWithoutCaption.java @@ -0,0 +1,92 @@ +package com.vaadin.tests.components.abstractfield; + +import java.util.HashSet; +import java.util.Set; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbsoluteLayout; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.ComponentContainer; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Field; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class RequiredIndicatorForFieldsWithoutCaption extends AbstractTestUI { + private Set<Field> fields = new HashSet<Field>(); + + @Override + protected void setup(VaadinRequest request) { + + CheckBox required = new CheckBox("Fields required", true); + required.setImmediate(true); + required.addValueChangeListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + boolean required = (Boolean) event.getProperty().getValue(); + for (Field f : fields) { + f.setRequired(required); + } + } + }); + addComponent(required); + addComponent(createWrappedTextField(new GridLayout(2, 1))); + addComponent(createWrappedTextField(new VerticalLayout())); + addComponent(createWrappedTextField(new HorizontalLayout())); + AbsoluteLayout al = new AbsoluteLayout(); + al.setWidth("400px"); + al.setHeight("100px"); + addComponent(createWrappedTextField(al)); + addComponent(createWrappedTextField(new CssLayout())); + } + + /** + * @since + * @param gridLayout + * @return + */ + private Component createWrappedTextField(ComponentContainer container) { + TextField tf = new TextField(); + tf.setRequired(true); + tf.setWidth(200, Unit.PIXELS); + fields.add(tf); + container.addComponent(new Label(container.getClass().getSimpleName())); + container.addComponent(tf); + if (container instanceof AbsoluteLayout) { + ((AbsoluteLayout) container).getPosition(tf).setLeft(100.0f, + Unit.PIXELS); + ((AbsoluteLayout) container).getPosition(tf).setTop(50.0f, + Unit.PIXELS); + } + + return container; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "Test for ensuring that the required indicator is visible for fields even when they would not otherwise have a caption"; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return 12077; + } +} |