/** For internal use only. May be removed or replaced in the future. */
public void setMaxLength(int newMaxLength) {
- if (newMaxLength >= 0 && newMaxLength != maxLength) {
- maxLength = newMaxLength;
- updateMaxLength(maxLength);
- } else if (maxLength != -1) {
- maxLength = -1;
- updateMaxLength(maxLength);
+ if (newMaxLength == maxLength) {
+ return;
}
-
+ maxLength = newMaxLength;
+ updateMaxLength(maxLength);
}
/**
- * This method is reponsible for updating the DOM or otherwise ensuring that
- * the given max length is enforced. Called when the max length for the
+ * This method is responsible for updating the DOM or otherwise ensuring
+ * that the given max length is enforced. Called when the max length for the
* field has changed.
*
* @param maxLength
--- /dev/null
+<?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.textfield.TextFieldMaxLengthRemovedFromDOM?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertAttribute</td>
+ <td>vaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]@maxlength</td>
+ <td>11</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]</td>
+ <td>118,13</td>
+</tr>
+<tr>
+ <td>assertAttribute</td>
+ <td>vaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]@maxlength</td>
+ <td>11</td>
+</tr>
+<tr>
+ <td>type</td>
+ <td>vaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]</td>
+ <td>hello</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/domChild[0]/domChild[1]</td>
+ <td>172,60</td>
+</tr>
+<tr>
+ <td>assertAttribute</td>
+ <td>vaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]@maxlength</td>
+ <td>11</td>
+</tr>
+</tbody></table>
+</body>
+</html>
--- /dev/null
+package com.vaadin.tests.components.textfield;
+
+import com.vaadin.event.FieldEvents;
+import com.vaadin.event.FieldEvents.FocusEvent;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.TextField;
+
+public class TextFieldMaxLengthRemovedFromDOM extends TestBase {
+
+ @Override
+ protected void setup() {
+ final TextField tf = new TextField();
+ tf.setMaxLength(11);
+ tf.setRequired(true);
+ tf.setImmediate(true);
+ addComponent(tf);
+
+ tf.addListener(new FieldEvents.FocusListener() {
+
+ public void focus(FocusEvent event) {
+ // Resetting Max length should not remove maxlength attribute
+ tf.setMaxLength(11);
+ }
+ });
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Maxlength attribute should not dissappear from the DOM when I focus the text field.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 9940;
+ }
+
+}