Sandbox: JavaScript

Prompts the user to confirm an action. Can be applied to a form control or a link.

Basic Usage

<a class="btn btn-default" data-confirm-options="{"content":"You sure you wanna do that?"}" data-trigger="confirm" href="/sandbox/JavaScript/Delegators/Delegator.Confirm">Reload this page</a>

The Double Check

For those actions you really want the user to be sure about, you can make them confirm twice.

<a class="btn btn-default" data-confirm-options="{"content":"You sure you wanna do that?","doubleCheck":true}" data-trigger="confirm" href="http://foxnews.com">Visit Fox News</a>

HTML In Your Prompt

If you want to include some basic HTML, don't use the content option, use the body option.

<a class="btn btn-default" data-confirm-options="{"body":"\u003Cp\u003EYou sure you wanna do that?\u003C/p\u003E\u003Col\u003E\u003Cli\u003EGoogle is better.\u003C/li\u003E\u003Cli\u003ESee #1\u003C/li\u003E\u003C/ol\u003E","doubleCheck":true}" data-trigger="confirm" href="http://foxnews.com">Visit Bing</a>

Specifying a Method Other Than GET

If you specify a value for data-method (a Rails convention) then this filter will create a form out of your link and submit it with the approrpiate action. Here, a post:

<a class="btn btn-default" data-confirm-options="{"content":"Post some stuff?"}" data-method="post" data-trigger="confirm" href="/sandbox/echo_html?html=%3Cp%3EYou+posted+it%21+%3Ca+href%3D%27%2Fsandbox%2FJavaScript%2FDelegators%2FDelegator.Confirm%27%3EGo+back%3C%2Fa%3E.%3C%2Fp%3E">Post it!</a>

As a Submit Button

All the examples above apply the trigger to links. Here's what it looks like in a form.

<form action="/sandbox/echo_html">
  <input type="hidden" name="html" value="<p>You posted it! <a href='/sandbox/JavaScript/Delegators/Delegator.Confirm'>Go back</a>.</p>">
  <input type="submit" class="btn btn-default" name="send" value="Send w/o prompting"/>
  <input type="submit" class="btn btn-default" name="send" value="Send w/ prompting" data-trigger="confirm" data-confirm-content="Post some stuff?"/>
</form>

Behavior Options

These options apply only to the data- tag invocation.

Name type default description
doubleCheck boolean false If true requires the user to confirm twice. They gotta really mean it.
authInput string '#auth_form_id input[name=authenticity_token]' Rails requires that forms have authenticity tokens. The expectation is that this form will be in your layout somewhere, hidden.
form string ~ Selector to find the form the element, when confirmed, submits. Not required for regular submit buttons, but this allows you to make links (or anything else) that will submit the form.
caption string 'Confirm' The caption in the popup.
content string ~ The body text of the popup. See also: the body option below.
body string ~ Same as caption but not wrapped in a p tag, so can contain any HTML you like.
data-method string ~ The method to submit the link. This is a rails convention.
Note This is not a property of the behavior's configration like everything else here. This setting is a data-method property on the element.