com.gargoylesoftware.htmlunit.javascript.host.html.FormField Maven / Gradle / Ivy
/*
* Copyright (c) 2002-2016 Gargoyle Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gargoylesoftware.htmlunit.javascript.host.html;
import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter;
import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.Function;
/**
* Base class for all JavaScript object corresponding to form fields.
*
* @author Mike Bowler
* @author Christian Sell
* @author Marc Guillemot
* @author Chris Erskine
* @author Ahmed Ashour
*/
@JsxClass(isJSObject = false, isDefinedInStandardsMode = false)
public class FormField extends FormChild {
/**
* Sets the associated DOM node and sets the enclosing form as parent scope of the current element.
* @see com.gargoylesoftware.htmlunit.javascript.SimpleScriptable#setDomNode(DomNode)
* @param domNode the DOM node
*/
@Override
public void setDomNode(final DomNode domNode) {
super.setDomNode(domNode);
final HtmlForm form = ((HtmlElement) domNode).getEnclosingForm();
if (form != null) {
setParentScope(getScriptableFor(form));
}
}
/**
* Returns the value of the JavaScript attribute {@code value}.
*
* @return the value of this attribute
*/
@JsxGetter
public String getValue() {
return getDomNodeOrDie().getAttribute("value");
}
/**
* Sets the value of the JavaScript attribute {@code value}.
*
* @param newValue the new value
*/
@JsxSetter
public void setValue(final Object newValue) {
getDomNodeOrDie().setAttribute("value", Context.toString(newValue));
}
/**
* Returns the value of the JavaScript attribute {@code name}.
*
* @return the value of this attribute
*/
@JsxGetter
public String getName() {
return getDomNodeOrDie().getAttribute("name");
}
/**
* Sets the value of the JavaScript attribute {@code name}.
*
* @param newName the new name
*/
@JsxSetter
public void setName(final String newName) {
getDomNodeOrDie().setAttribute("name", newName);
}
/**
* Sets the {@code onchange} event handler for this element.
* @param onchange the {@code onchange} event handler for this element
*/
@Override
@JsxSetter(@WebBrowser(IE))
public void setOnchange(final Object onchange) {
setEventHandlerProp("onchange", onchange);
}
/**
* Returns the {@code onchange} event handler for this element.
* @return the {@code onchange} event handler for this element
*/
@Override
@JsxGetter(@WebBrowser(IE))
public Function getOnchange() {
return getEventHandler("onchange");
}
/**
* {@inheritDoc} Overridden to modify browser configurations.
*/
@Override
@JsxGetter
public boolean getDisabled() {
return super.getDisabled();
}
/**
* {@inheritDoc} Overridden to modify browser configurations.
*/
@Override
@JsxSetter
public void setDisabled(final boolean disabled) {
super.setDisabled(disabled);
}
}