1 38 package com.gargoylesoftware.htmlunit.javascript.host; 39 40 import org.xml.sax.helpers.AttributesImpl ; 41 42 import com.gargoylesoftware.htmlunit.html.HtmlInput; 43 import com.gargoylesoftware.htmlunit.html.InputElementFactory; 44 45 54 public class Input extends FormField { 55 56 private static final long serialVersionUID = 3712016051364495710L; 57 58 59 62 public Input() { 63 } 64 65 66 71 public void jsConstructor() { 72 } 73 74 79 public void jsxSet_type(final String newType) { 80 HtmlInput input = getHtmlInputOrDie(); 81 82 if (!input.getTypeAttribute().equalsIgnoreCase(newType)) { 83 final AttributesImpl attributes = readAttributes(input); 84 final int index = attributes.getIndex("type"); 85 attributes.setValue(index, newType); 86 87 final HtmlInput newInput = (HtmlInput) InputElementFactory.instance 88 .createElement(input.getPage(), "input", attributes); 89 90 if(input.getPreviousSibling() != null) { 93 input.replace(newInput); 96 } 97 else { 98 input = newInput; 102 } 103 104 input.setScriptObject(null); 105 setDomNode(newInput, true); 106 } 107 } 108 109 118 public void jsxSet_checked( final boolean checked ) { 119 final HtmlInput input = getHtmlInputOrDie(); 120 final String type = input.getTypeAttribute().toLowerCase(); 121 if (type.equals("checkbox") || type.equals("radio")){ 122 input.setChecked(checked); 123 } 124 else { 125 getLog().debug( "Input.jsxSet_checked(" + checked 126 + ") was called for class " + getClass().getName() ); 127 } 128 } 129 130 134 protected HtmlInput getHtmlInputOrDie() { 135 return (HtmlInput) getHtmlElementOrDie(); 136 } 137 138 139 147 public boolean jsxGet_checked() { 148 final HtmlInput input = getHtmlInputOrDie(); 149 final String type = input.getTypeAttribute().toLowerCase(); 150 if (type.equals("checkbox") || type.equals("radio")){ 151 return input.isChecked(); 152 } 153 else { 154 getLog().warn( "Input.jsxGet_checked() was called for class " + getClass().getName() ); 155 return false; 156 } 157 } 158 159 } 160 161 | Popular Tags |