Easy Form

BeakerX has a Groovy API for creating forms that the user can fill in and trigger execution. It's easy to create a form with it, and easy to access the values entered. Just create a form object, add fields to it, and then return it so it's displayed for the user to interact with.

The 2nd parameter to the addButton method specifies a tag. All cells with that tag are executed when the button is pressed. Use the View → Cell Toolbar → Tags menu item to view and edit tags.

In [ ]:
f = new EasyForm("Form and Run")
f['first'] = "First"
f['last'] = "Last"
f.addButton("Go!", "run")

You can access the values from the form by treating it as an array indexed on the field names:

In [ ]:
f['last'].reverse() + '...' + f['first']

The array works both ways, so you set default values on the fields by writing the array:

In [ ]:
f['first'] = 'Beaker'
f['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 [ ]:
f1 = new EasyForm("Form and Run")
f1.addTextField("first", 15)
f1.addTextField("last", 15).onInit({f1['last'] = "setinit1"}).onChange({text -> f1['first'] = text + " extra"})
button = f1.addButton("action", "action_button")
button.actionPerformed = {f1['last'] = 'action done'}    
In [ ]:
f1['last'] + ", " + f1['first']
In [ ]:
f1['last'] = "new Value"
In [ ]:
f1['first'] = "new Value2"

All Kinds of Fields

In [ ]:
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")
options = ["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.addButton("Go!", "run2")
In [ ]:
result = [:]
g.keySet().each {
  result[it] = g[it]

Dates are

In [ ]:
gdp = new EasyForm("Field Types")
In [ ]:


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

JupyterJSWidgets work with EasyForm

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

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

w = new IntSlider()

widgetForm = new EasyForm("pyhton widgets")
widgetForm.addButton("Press", "widget_test")
In [ ]: