All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.webfolder.ui4j.api.dom.Form Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
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()");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy