Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Added option to select text by default on edit

  • Loading branch information...
commit a7cbab69952eec7c39acbe5e14fafe9b6b443e62 1 parent 542288a
@jisk authored
1  README.markdown
@@ -67,6 +67,7 @@ The `on_the_spot_edit` also accepts options:
* `:data`: for select, the lookup-data, should be in an array of id-value pairs. E.g. `[[1, 'ok'], [2, 'not ok'], [3, 'not decided']]`.
* `:loadurl`: for select, an url that will return the data in JSON format (use instead of `:data`)
* `:url`: URL to post to if you don't want to use the standard routes
+* `:selected`: Text selected by default on edit (boolean, default is false)
For the texts: if a text is not specified, the default is taken from the `on_the_spot.en.yml` (or your current language).
4 lib/generators/on_the_spot/install/templates/on_the_spot.js
@@ -17,13 +17,15 @@ $(document).ready(function() {
select_data = el.attr('data-select'),
rows = el.attr('data-rows'),
columns = el.attr('data-columns'),
- load_url = el.attr('data-loadurl');
+ load_url = el.attr('data-loadurl'),
+ selected = el.attr('data-selected');
var options = {
tooltip: tooltip_text,
placeholder: tooltip_text,
cancel: cancel_text,
submit: ok_text,
+ select: selected,
onerror: function (settings, original, xhr) {
//just show the error-msg for now
4 lib/on_the_spot/on_the_spot_helpers.rb
@@ -17,6 +17,7 @@ class OnTheSpotMissingParameters < StandardError; end
# display_text : either overrule the normal display-value, or needed when using loadurl
# data : (for select) an array of options in the form [id, value]
# url : (optional) URL to post to if you don't want to use the standard routes
+ # selected : (optional) boolean, text selected on edit
def on_the_spot_edit(object, field, options={})
#!!! to do: translate options to data-fields
# Possible fields:
@@ -63,7 +64,8 @@ def on_the_spot_edit(object, field, options={})
html_options[:'data-cancel'] = options[:cancel_text]
html_options[:'data-tooltip'] = options[:tooltip]
html_options[:'data-auth'] = form_authenticity_token if defined? form_authenticity_token
+ html_options[:'data-selected'] = options[:selected]
content_tag("span", html_options) do
if options[:display_text]
Please sign in to comment.
Something went wrong with that request. Please try again.