prototype: Form.Element.activate shouldn't raise an exception when the form or field is hidden.

This commit is contained in:
Sam Stephenson 2007-01-18 23:07:02 +00:00
parent c89875ce8c
commit 84901897c8
3 changed files with 19 additions and 6 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Form.Element.activate shouldn't raise an exception when the form or field is hidden. [sam]
* Remove support for "throw $continue" in Enumerable. Use "return" instead. [sam]
* Update HEADER to reflect new URL. [sam]

View File

@ -132,10 +132,12 @@ Form.Element.Methods = {
activate: function(element) {
element = $(element);
element.focus();
if (element.select && ( element.tagName.toLowerCase() != 'input' ||
!['button', 'reset', 'submit'].include(element.type) ) )
element.select();
try {
element.focus();
if (element.select && (element.tagName.toLowerCase() != 'input' ||
!['button', 'reset', 'submit'].include(element.type)))
element.select();
} catch (e) {}
return element;
},

View File

@ -86,6 +86,10 @@
<input type="text" name="focus_text" id="focus_text" value="Hello" />
</form>
<form id="form_focus_hidden" style="display: none">
<input type="text" />
</form>
<!-- Tests follow -->
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
@ -209,13 +213,18 @@
Form.focusFirstElement('form_focus');
if(document.selection) assertEqual('', getSelection(element));
// Form.Field.activate shouldn't select text on buttons
// Form.Element.activate shouldn't select text on buttons
element = $('focus_text');
assertEqual('', getSelection(element));
// Form.Field.activate should select text on text input elements
// Form.Element.activate should select text on text input elements
element.activate();
assertEqual('Hello', getSelection(element));
// Form.Element.activate shouldn't raise an exception when the form or field is hidden
assertNothingRaised(function() {
$('form_focus_hidden').focusFirstElement();
});
}},
testFormGetElements: function() {with(this) {