diff --git a/README.md b/README.md index d386e2eb..f2d7e778 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ Options: - **:class**: Additional classes to apply to the best_in_place span. Accepts either a string or Array of strings - **:value**: Customize the starting value of the inline input (defaults to to the field's value) - **:id**: The HTML id of the best_in_place span. If not specified one is automatically generated. +- **:id_appendix**: Adds '_value' to the autogenerated id - **:param**: If you wish to specific the object explicitly use this option. - **:confirm**: If set to true displays a confirmation message when abandoning changes (pressing the escape key). - **:skip_blur**: If set to true, blurring the input will not cause changes to be abandoned in textareas. @@ -386,8 +387,8 @@ As of now, a total of four helpers are available. There is one for each of the f These four helpers are listed below: -* **bip_area(model, attr, new_value)** -* **bip_text(model, attr, new_value)** +* **bip_area(model, attr, new_value, options = {})** +* **bip_text(model, attr, new_value, options = {})** * **bip_bool(model, attr)** * **bip_select(model, attr, name)** @@ -396,6 +397,8 @@ The parameters are defined here (some are method-specific): * **model**: the model to which this action applies. * **attr**: the attribute of the model to which this action applies. * **new_value** (only **bip_area** and **bip_text**): the new value with which to fill the BIP field. +* **options** (only **bip_area** and **bip_text**): Holds information like the id_appendix for id creation + * **name** (only **bip_select**): the name to select from the dropdown selector. --- diff --git a/lib/best_in_place/helper.rb b/lib/best_in_place/helper.rb index 1e5ec5f2..9b7667db 100644 --- a/lib/best_in_place/helper.rb +++ b/lib/best_in_place/helper.rb @@ -31,7 +31,8 @@ def best_in_place(object, field, opts = {}) end options[:class] = ['best_in_place'] + Array(opts[:class] || opts[:classes]) - options[:id] = opts[:id] || BestInPlace::Utils.build_best_in_place_id(real_object, field) + options[:data]['id_appendix'] = opts[:id_appendix].presence + options[:id] = opts[:id] || BestInPlace::Utils.build_best_in_place_id(real_object, field, options[:data]['id_appendix']) pass_through_html_options(opts, options) @@ -85,7 +86,7 @@ def pass_through_html_options(opts, options) :activator, :cancel_button, :cancel_button_class, :html_attrs, :inner_class, :nil, :object_name, :ok_button, :ok_button_class, :display_as, :display_with, :path, :value, :use_confirm, :confirm, :sanitize, :raw, :helper_options, :url, :place_holder, :class, - :as, :param, :container] + :as, :param, :container, :id_appendix] uknown_keys = opts.keys - known_keys uknown_keys.each { |key| options[key] = opts[key] } end diff --git a/lib/best_in_place/test_helpers.rb b/lib/best_in_place/test_helpers.rb index 68f47b3b..51d1b8a8 100644 --- a/lib/best_in_place/test_helpers.rb +++ b/lib/best_in_place/test_helpers.rb @@ -2,8 +2,8 @@ module BestInPlace module TestHelpers include ActionView::Helpers::JavaScriptHelper - def bip_area(model, attr, new_value) - id = BestInPlace::Utils.build_best_in_place_id model, attr + def bip_area(model, attr, new_value, options = {}) + id = BestInPlace::Utils.build_best_in_place_id model, attr, options[:id_appendix] find("##{id}").trigger('click') execute_script <<-JS $("##{id} form textarea").val('#{escape_javascript new_value.to_s}'); @@ -12,8 +12,8 @@ def bip_area(model, attr, new_value) wait_for_ajax end - def bip_text(model, attr, new_value) - id = BestInPlace::Utils.build_best_in_place_id model, attr + def bip_text(model, attr, new_value, options = {}) + id = BestInPlace::Utils.build_best_in_place_id model, attr, options[:id_appendix] find("##{id}").click execute_script <<-JS $("##{id} input[name='#{attr}']").val('#{escape_javascript new_value.to_s}'); diff --git a/lib/best_in_place/utils.rb b/lib/best_in_place/utils.rb index 9f6651ce..83d05eee 100644 --- a/lib/best_in_place/utils.rb +++ b/lib/best_in_place/utils.rb @@ -1,7 +1,7 @@ module BestInPlace module Utils #:nodoc: module_function - def build_best_in_place_id(object, field) + def build_best_in_place_id(object, field, appendix = nil) case object when Symbol, String "best_in_place_#{object}_#{field}" @@ -9,6 +9,7 @@ def build_best_in_place_id(object, field) id = "best_in_place_#{object_to_key(object)}" id << "_#{object.id}" if object.persisted? id << "_#{field}" + id << "_#{appendix}" if !appendix.nil? id end end