com.gargoylesoftware.htmlunit.javascript.host.html.FormField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of htmlunit Show documentation
Show all versions of htmlunit Show documentation
A headless browser intended for use in testing web-based applications.
/*
* Copyright (c) 2002-2018 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 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 net.sourceforge.htmlunit.corejs.javascript.Context;
/**
* 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)
public class FormField extends HTMLElement {
/**
* 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().getAttributeDirect("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().getAttributeDirect("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);
}
/**
* {@inheritDoc} Overridden to modify browser configurations.
*/
@Override
@JsxGetter
public boolean isDisabled() {
return super.isDisabled();
}
/**
* {@inheritDoc} Overridden to modify browser configurations.
*/
@Override
@JsxSetter
public void setDisabled(final boolean disabled) {
super.setDisabled(disabled);
}
/**
* Returns the value of the JavaScript {@code form} attribute.
*
* @return the value of the JavaScript {@code form} attribute
*/
@JsxGetter
public HTMLFormElement getForm() {
final HtmlForm form = getDomNodeOrDie().getEnclosingForm();
if (form == null) {
return null;
}
return (HTMLFormElement) getScriptableFor(form);
}
}