From: <asa...@us...> - 2017-05-31 10:46:44
|
Revision: 14510 http://sourceforge.net/p/htmlunit/code/14510 Author: asashour Date: 2017-05-31 10:46:40 +0000 (Wed, 31 May 2017) Log Message: ----------- TextArea.minLength Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java 2017-05-31 10:37:30 UTC (rev 14509) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java 2017-05-31 10:46:40 UTC (rev 14510) @@ -313,11 +313,46 @@ } catch (final NumberFormatException e) { getDomNodeOrDie().setAttribute("maxLength", "0"); - return; } } /** + * Returns the minimum number of characters in this text area. + * @return the minimum number of characters in this text area + */ + @JsxGetter({CHROME, FF}) + public Object getMinLength() { + final String minLength = getDomNodeOrDie().getAttribute("minLength"); + + try { + return Integer.parseInt(minLength); + } + catch (final NumberFormatException e) { + return -1; + } + } + + /** + * Sets minimum number of characters in this text area. + * @param minLength minimum number of characters in this text area. + */ + @JsxSetter({CHROME, FF}) + public void setMinLength(final String minLength) { + try { + final int i = Integer.parseInt(minLength); + + if (i < 0 ) { + throw Context.throwAsScriptRuntimeEx( + new NumberFormatException("New value for minLength '" + minLength + "' is smaller than zero.")); + } + getDomNodeOrDie().setAttribute("minLength", minLength); + } + catch (final NumberFormatException e) { + getDomNodeOrDie().setAttribute("minLength", "0"); + } + } + + /** * Returns the {@code placeholder} attribute. * @return the {@code placeholder} attribute */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java 2017-05-31 10:37:30 UTC (rev 14509) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java 2017-05-31 10:46:40 UTC (rev 14510) @@ -602,7 +602,7 @@ @Test @Alerts(DEFAULT = {"-1", "null", "32", "32", "-1", "ms"}, IE = {"2147483647", "null", "32", "32", "2147483647", "ms"}) - public void getMaxLength() throws Exception { + public void maxLength() throws Exception { final String html = "<html>\n" + "<head><title>foo</title>\n" @@ -618,7 +618,7 @@ + " </script>\n" + "</head>\n" + "<body onload='test()'>\n" - + " <form name='form1' method='post' >\n" + + " <form name='form1' method='post'>\n" + " <textarea name='textarea1'></textarea>\n" + " <textarea name='textarea2' maxLength='32'></textarea>\n" + " <textarea name='textarea3' maxLength='ms'></textarea>\n" @@ -632,6 +632,38 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = {"-1", "null", "32", "32", "-1", "ms"}, + IE = {"undefined", "null", "undefined", "32", "undefined", "ms"}) + public void minLength() throws Exception { + final String html + = "<html>\n" + + "<head><title>foo</title>\n" + + " <script>\n" + + " function test() {\n" + + " alert(document.form1.textarea1.minLength);\n" + + " alert(document.form1.textarea1.getAttribute('minLength'));\n" + + " alert(document.form1.textarea2.minLength);\n" + + " alert(document.form1.textarea2.getAttribute('minLength'));\n" + + " alert(document.form1.textarea3.minLength);\n" + + " alert(document.form1.textarea3.getAttribute('minLength'));\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <form name='form1' method='post'>\n" + + " <textarea name='textarea1'></textarea>\n" + + " <textarea name='textarea2' minLength='32'></textarea>\n" + + " <textarea name='textarea3' minLength='ms'></textarea>\n" + + " </form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = {"10", "10", "error", "10", "10", "0", "0"}, IE = {"10", "10", "-1", "-1", "0", "0"}) public void setMaxLength() throws Exception { |