From: <rb...@us...> - 2013-11-26 20:09:57
|
Revision: 8809 http://sourceforge.net/p/htmlunit/code/8809 Author: rbri Date: 2013-11-26 20:09:54 +0000 (Tue, 26 Nov 2013) Log Message: ----------- Setting the value property of a select element does not trigger the onfocus event handler Issue 1558 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElement.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-11-26 18:41:09 UTC (rev 8808) +++ trunk/htmlunit/src/changes/changes.xml 2013-11-26 20:09:54 UTC (rev 8809) @@ -8,8 +8,10 @@ <body> <release version="2.14" date="???" description="Bugfixes"> - Enctype form attribute returns wrong default value - + <action type="fix" dev="rbri" issue="1558"> + JavaScript: Setting the value property of a select element does not trigger + the onfocus event handler. + </action> <action type="fix" dev="rbri" issue="1560"> JavaScript: Fixed enctype form property default value. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-11-26 18:41:09 UTC (rev 8808) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-11-26 20:09:54 UTC (rev 8809) @@ -1926,11 +1926,11 @@ * @see WebAssert#assertAllTabIndexAttributesSet(HtmlPage) */ public boolean setFocusedElement(final HtmlElement newElement, final boolean windowActivated) { - if (elementWithFocus_ == newElement && (!windowActivated)) { + if (elementWithFocus_ == newElement && !windowActivated) { // nothing to do return true; } - else if (newElement != null && newElement.getPage() != this) { + if (newElement != null && newElement.getPage() != this) { throw new IllegalArgumentException("Can't move focus to an element from a different page."); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java 2013-11-26 18:41:09 UTC (rev 8808) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java 2013-11-26 20:09:54 UTC (rev 8809) @@ -255,10 +255,30 @@ * @return the page contained in the current window as returned * by {@link com.gargoylesoftware.htmlunit.WebClient#getCurrentWindow()} */ + public <P extends Page> P setSelectedAttribute(final String optionValue, final boolean isSelected) { + return setSelectedAttribute(optionValue, isSelected, true); + } + + /** + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> + * + * Sets the "selected" state of the specified option. If this "select" element + * is single-select, then calling this method will deselect all other options. + * + * Only options that are actually in the document may be selected. + * + * @param isSelected true if the option is to become selected + * @param optionValue the value of the option that is to change + * @param invokeOnFocus whether to set focus or not. + * @param <P> the page type + * @return the page contained in the current window as returned + * by {@link com.gargoylesoftware.htmlunit.WebClient#getCurrentWindow()} + */ @SuppressWarnings("unchecked") - public <P extends Page> P setSelectedAttribute(final String optionValue, final boolean isSelected) { + public <P extends Page> P setSelectedAttribute(final String optionValue, + final boolean isSelected, final boolean invokeOnFocus) { try { - return (P) setSelectedAttribute(getOptionByValue(optionValue), isSelected); + return (P) setSelectedAttribute(getOptionByValue(optionValue), isSelected, invokeOnFocus); } catch (final ElementNotFoundException e) { if (hasFeature(SELECT_DESELECT_ALL_IF_SWITCHING_UNKNOWN)) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElement.java 2013-11-26 18:41:09 UTC (rev 8808) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElement.java 2013-11-26 20:09:54 UTC (rev 8809) @@ -357,7 +357,7 @@ */ @Override public void setValue(final String newValue) { - getHtmlSelect().setSelectedAttribute(newValue, true); + getHtmlSelect().setSelectedAttribute(newValue, true, false); } /** |