Scala API to EasyForm

In [ ]:
val form : EasyForm = new com.twosigma.beakerx.scala.easyform.EasyForm("Form and Run")
form.addTextField("first")
form.put("first", "First")
form.addTextField("last")
form.put("last", "Last")
form.addButton("Go!", "run")

form

You can access the values from the form with get method:

In [ ]:
"Good morning " + form.get("first") + " " + form.get("last")

You can set default values on the fields with put method:

In [ ]:
form.put("first", "Beaker")
form.put("last", "Berzelius")

Event Handlers for Smarter Forms

You can use onInit and onChange to handle component events. For button events use actionPerformed or addAction.

In [ ]:
//You can use onInit and onChange to handle component events. For button events use actionPerfromed or addAction.
val f1 = new EasyForm("Form and Run")
val first = f1.addTextField("first", 15)
val last = f1.addTextField("last", 15).onInit(new EasyFormListener {
      override def execute(value: String): Unit = {
        f1.put("last", "setinit1");
      }
    }).onChange(new EasyFormListener {
      override def execute(value: String): Unit = {
        first.setValue(f1.get("last") + " extra");
      }
    });
val button = f1.addButton("action", "action_button")
button.actionPerformed = new EasyFormListener {
      override def execute(value: String): Unit = f1.put("last", "action done");
}

f1
In [ ]:
f1.get("last") + ", " + f1.get("first")
In [ ]:
f1.put("last", "new Value")
In [ ]:
f1.put("first", "new Value2")

All Kinds of Fields

In [ ]:
val g = new EasyForm("Field Types")
g.addTextField("Short Text Field", 10)
g.addTextField("Text Field")
g.addPasswordField("Password Field", 10)
g.addTextArea("Text Area")
g.addTextArea("Tall Text Area", 10, 5)
g.addCheckBox("Check Box")
val options = Seq("a", "b", "c", "d")
g.addComboBox("Combo Box", options)
g.addComboBox("Editable Combo", options, true)

g.addList("List", options)
g.addList("List Single", options, false)
g.addList("List Two Row", options, 2)

g.addCheckBoxes("Check Boxes", options)
g.addCheckBoxes("Check Boxes H", options, EasyForm.HORIZONTAL)

g.addRadioButtons("Radio Buttons", options)
g.addRadioButtons("Radio Buttons H", options, EasyForm.HORIZONTAL)

g.addDatePicker("Date")

g.addButton("Go!", "run2")
g
In [ ]:
import java.util.HashMap
import java.util.function.Consumer

val result = new HashMap[String, Object]()
g.keySet().forEach(
new Consumer[String] {
    override def accept(key: String): Unit = {
      result.put(key, g.get(key))
    }
  }
)
result

Dates

In [ ]:
val gdp = new EasyForm("Field Types")
val date = gdp.addDatePicker("Date")
gdp
In [ ]:
gdp.get("Date")

SetDate

In [ ]:
import java.util.Date

val easyForm = new EasyForm("Field Types")
// Setup date via String (format is yyyyMMdd) also works
easyForm.addDatePicker("Date").setDate(new Date())
easyForm

Default Values

In [ ]:
val h = new EasyForm("Default Values")
h.addTextArea("Default Value", "Initial value")
h.addCheckBox("Default Checked", true)
h.addButton("Press", "check")
h
In [ ]:
val result = new HashMap[String, Object]()
h.keySet().forEach(
new Consumer[String] {
    override def accept(key: String): Unit = {
      result.put(key, h.get(key))
    }
  }
)
result

JupyterJSWidgets work with EasyForm

The widgets from JupyterJSWidgets are compatible and can appear in forms.

In [ ]:
import com.twosigma.beakerx.widget.IntSlider

val w = new IntSlider()

val widgetForm = new EasyForm("pyhton widgets")
widgetForm.addButton("Press", "widget_test")
widgetForm.addWidget("IntSlider",w)
widgetForm
In [ ]:
widgetForm.get("IntSlider")
In [ ]: