Feedback on Prompt.jsm

Wesley Johnston wjohnston at
Wed May 22 16:05:09 PDT 2013

I put up a patch in bug 875119 to add a new Prompt.jsm module to Fennec. The idea is to expose some of the extra features that prompts can have (in our own code and in addons), without requiring them to learn (or tying us to) a particular JSON message format. Before we land something like this, I'd love to get some feedback from anyone interested.

This requires the async prompt service code i'm writing in bug 870062 to work. The API is pretty self explanatory. Most (except show) methods return the prompt object so you can chain them. Quick overview:

    setTitle: function(aTitle)
    setMessage: function(aMessage)

    // adds buttons at the bottom of the dialog.
    // throws if you try to add more than three buttons
    // XXX Is this confusing with the other inputs below?
    addButton: function(aLabel)

    // order of calling these dictates the order they're shown
    addCheckbox: function(aLabel, aChecked)
    addTextbox: function(aValue, aHint, aAutofocus)
    addPassword: function(aValue, aHint, aAutofocus)
    addMenulist: function(aValues)
    // XXX: Add date-time inputs...

    show: function(callback)

    // aItems can be an array of strings or objects
    // these should(?) (but don't currently) throw if you've set a message
    // or other inputs as we currently don't support showing both
    // simultaneously. I'd like to fix that someday though.
    setSingleChoiceItems: function(aItems) 
    setMultiChoiceItems: function(aItems)


// Show a prompt with a title, message, checkbox, and one button
var p = new Prompt(window) // in case we ever have tab modal prompts
            .setMessage("this is a message")
            .addCheckbox("My checkbox", true, "myCheckbox")
            .show(function(data) {
  // the return value isn't well formalized yet...
  var button = data.button;
  var checked = data.myCheckbox;

// Show a prompt with a list of single choice items and a title
var p = new Prompt(window);
p.setTitle("My Title");
p.setSingleChoiceItems(["One", "Two", "Three"]); {
  var indexClicked = data.button;

// Show a prompt with a list of multi choice items and a title
var p = new Prompt(window);
p.setTitle("My Title");
  { label: "One", id: 1, disabled: true },
  // Shows as a group header with children underneath
  { label: "Two", id: 2, children: [
    { label: "Three", id: 3 }
  // We also support sub-menus, but I'm not sure how to expose them.
  // This is stubbed right now so that we can at least show the submenu arrow
  { label: "Four", id 4, submenu: true },
]).show(function(data) {
  // button contains an array of booleans indicating whether
  // a row is now selected or unselected...
  var selected = data.button;

More information about the mobile-firefox-dev mailing list