Module: RailsBootstrapWidgets::ModalHelper
- Defined in:
- app/helpers/rails-bootstrap-widgets/modal_helper.rb
Instance Method Summary collapse
-
#modal_form_widget(options = {}, &block) ⇒ Object
To create modal form in a view, put your fields into
modal_form_widget(options = {}, &block)
. -
#modal_view_widget(options = {}, &block) ⇒ Object
To create modal window in a view, put its content into
modal_view_widget(options = {}, &block)
.
Instance Method Details
#modal_form_widget(options = {}, &block) ⇒ Object
To create modal form in a view, put your fields into modal_form_widget(options = {}, &block)
.
modal_form_widget (
title: 'modal window title', # required
action: 'path to corresponding route', # required
method: 'request method for the form', # "post" by default, "post", "get", "put" or "delete" extected
button: 'text on the submit button', # I18n.t("buttons.submit") by default
cancel: 'text on the cancel form button' # I18n.t("buttons.cancel") by default
) { "" } # html code of form fields
The widget puts a list of fields (inputs, selectors etc.) into a modal form window (presented by <form id='modal' class='modal fade'...>
) For example, the call
(title: 'Title', button: 'Button', method: :put, action: '/some_addr', cancel: "Cancel") { "content" }
Will provide html:
<form accept-charset="UTF-8" action="/some_addr" class="modal fade" data-remote="true" id="modal" method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓" />
</div>
<input id="_method" name="_method" type="hidden" value="put" />
<header class="modal-header">
<button aria-hidden="true" class="close" data-dismiss="modal" type="button">×</button>
<h1>Title</h1>
</header>
<div class="modal-body">content</div>
<div class="modal-footer">
<a href="#" aria-hidden="true" class="btn" data-dismiss="modal">Cancel</a>
<input class="btn btn-primary" id="submit" name="commit" type="submit" value="Button" />
</div>
</form>
37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/rails-bootstrap-widgets/modal_helper.rb', line 37 def ( = {}, &block) if ( = _prepare(, :form)) && (content = block_given? ? capture(&block) : nil) form_tag([:action], method: :post, id: "modal", class: "modal fade", remote: true) do (_hidden([:method]) << _header([:title]) << _body(content) << (:submit, [:button], [:cancel])).html_safe end else '' end end |
#modal_view_widget(options = {}, &block) ⇒ Object
To create modal window in a view, put its content into modal_view_widget(options = {}, &block)
.
modal_view_widget (
title: 'modal window title', # required
href: 'path for redirection to details', # required
redirect: true|false, # whether redirect button should be shown in the modal window footer (true by default),
button: 'text on the redirect button', # I18n.t("buttons.details") by default
cancel: 'text on the cancel form button' # I18n.t("buttons.cancel") by default
) { "" } # html code of form fields
The widget puts html code into a modal window (presented by <div id='modal' class='modal fade'>
) For example, the call
(title: 'Title', button: 'Button', href: '/some_addr', cancel: "Cancel") { "content" }
Will provide html:
<div class="modal fade" id="modal">
<header class="modal-header">
<button aria-hidden="true" class="close" data-dismiss="modal" type="button">×</button>
<h1>Title</h1>
</header>
<div class="modal-body">content</div>
<div class="modal-footer">
<a href="#" aria-hidden="true" class="btn" data-dismiss="modal">Cancel</a>
<a href="/some_addr" class="btn btn-primary">Button</a>
</div>
</div>
75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/rails-bootstrap-widgets/modal_helper.rb', line 75 def ( = {}, &block) content = block_given? ? capture(&block) : nil if ( = _prepare(, :view)) && content content_tag(:div, id: "modal", class: "modal fade") do (_header([:title]) << _body(content) << (:button, [:button], [:cancel], [:href], [:redirect])).html_safe end else '' end end |