io.webfolder.ui4j.api.dom.Form Maven / Gradle / Ivy
package io.webfolder.ui4j.api.dom;
import java.util.List;
import java.util.Optional;
public class Form {
private Element element;
public Form(Element element) {
this.element = element;
}
public void clear() {
List inputs = element.find("input, select, textarea");
for (Element next : inputs) {
String tag = next.getTagName();
if (tag.equals("input")) {
Optional attribute = next.getAttribute("type");
if (attribute.isPresent()) {
String type = attribute.get().trim();
if (type.equalsIgnoreCase("radio")) {
next.getRadioButton().get().setChecked(false);
} else if (type.equalsIgnoreCase("checkbox")) {
next.getCheckBox().get().setChecked(false);
} else if (type.equalsIgnoreCase("text")) {
next.setValue("");
}
} else {
next.setValue("");
}
} else if (tag.equals("select")) {
next.getSelect().get().clearSelection();
} else if (tag.equals("textarea")) {
next.setText("");
}
}
}
public Element getElement() {
return element;
}
public void submit() {
element.eval("this.submit()");
}
}