DA.Promptversion 0.5b | ||
This is the default prompt behavior. It just asks the user for input. The Prompt object is stored as the first JS variable, which is called in second example through |
This prompt:
|
This has options.cover set to 2, which disables other prompts upon activation. Also has a few more options for input. These can be any valid HTML or form controls and is set by options.body, which is just an ordinary HTML sting. The html (form controls) is wrapped inside the FORM tag, so if you submit() the prompt form, the input is actually sent (it behaves like a regular form). |
The DA.Prompt offers on-the-fly creation of user input forms and was developed as a way to expand the possibilities of a regular javascript prompt function.
DA.Prompt makes use of the famous prototype JS framework (required) and the scriptaculous extension (optional - enables draggable prompts and overlay opacity transitions). Files required can be downloaded at these web sites.
The main difference between DA.Prompt class and JS prompt function is, that JS prompt halts the execution of the script (same as alert fucntion) and JS prompt only offers one input field. DA.Prompt can be customized in any way you would actually want, as well as making your own custom CSS for the prompts, so you can match the visual to your needs.
myPromptVar.ask()
option | description | default |
---|---|---|
body (string) HTML | the html of the from. Note that the Prompt object is also accessible through form.Prompt so you CAN write something like this: body: '<input type="text" name="username" onchange="this.form.Prompt.triggerHandler('CheckUsername')" ... This would result in your custom options.onCheckUsername function firing whenever user changes the content of the input. |
'<br /><input type="text" name="userInput" value="" />' |
controls (object) | the buttons of the form ( key is the action, value is the label ) where action is the name of the on + action function to be triggered on click. The functions are not required. Actions are only appended to the defaults - you can override this by declaring custom Confirm and Cancel to change their labels, or by setting defaults to false, which would display only the user-defined buttons. syntax: { action1: 'label1', action2: 'label2' ... [, defaults: true|false ] } example: controls: { Bingo: 'Play' } this would render 3 buttons:
example: |
{ Confirm: "OK", Cancel:"Cancel" } |
onAction (functions) | Actions to trigger on prompt submission. The Action part is the name of the control button set by controls: {Action: 'button label' } The parameters passed to this function is the form and the prompt object, so defining the onAction function should look like this: onBingo: function(form, obj){ $(form).serialize(); alert(form.userInput.value); obj._deactivate(); obj._hide(); } |
onConfirm(), onCancel() |
title (string) | The name of the prompt "window" | document.title |
cover (integer) | The "cover" index
|
1 |
on + events |
Functions which fire on certain events. This is the list of events:
Parameters passed to these functions are the form DOM object (which you can serialize, test, modify just like an ordinary DOM#form obj), and the Prompt object, with its functions (so you can do stuff with the prompt, like _activate, triggerHandler, _destroy, ask, _hide). |
|
Options example
|
container |
div .promptContainer | |
ctrlContainer |
div .promptCtrlContainer | |
form |
form | |
isOpen |
bool | |
options |
Object | |
promptText |
string - prompt question | |
titleContainer |
div .promptTitleContainer | |
_activate |
function() | |
_deactivate |
function() | |
_destroy |
function() | |
_fold |
function() | |
_hide |
function() | |
_reset |
function() | |
_submit |
function() | |
ask |
function() | |
build |
function() | |
initialize |
function() | |
triggerHandler |
function() |