Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#542 Add True/False class changing for checkboxes #543

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/assets/javascripts/best_in_place.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ BestInPlaceEditor.prototype = {

case "checkbox":
$.each(this.values, function(index, arr){ if (String(arr[0]) === String(value)) editor.element.html(arr[1]); });
if (value)
{
editor.element.removeClass(editor.element.data("bip-false-class"));
editor.element.addClass(editor.element.data("bip-true-class"));
} else {
editor.element.removeClass(editor.element.data("bip-true-class"));
editor.element.addClass(editor.element.data("bip-false-class"));
}
break;

default:
Expand Down Expand Up @@ -326,7 +334,6 @@ BestInPlaceEditor.prototype = {
setHtmlAttributes: function () {
'use strict';
var formField = this.element.find(this.formType);

if (this.html_attrs) {
var attrs = this.html_attrs;
$.each(attrs, function (key, val) {
Expand Down
13 changes: 12 additions & 1 deletion lib/best_in_place/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ def best_in_place(object, field, opts = {})
options[:data]['bip-confirm'] = opts[:confirm].presence
options[:data]['bip-value'] = html_escape(value).presence

if type == :checkbox
options[:data]['bip-true-class'] = opts[:true_class]
options[:data]['bip-false-class'] = opts[:false_class]
if value == true.to_s
options[:class] = options[:class] << opts[:true_class]
else
options[:class] = options[:class] << opts[:false_class]
end
end


if opts[:raw]
options[:data]['bip-raw'] = 'true'
end
Expand Down Expand Up @@ -82,7 +93,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, :true_class, :false_class]
uknown_keys = opts.keys - known_keys
uknown_keys.each { |key| options[key] = opts[key] }
end
Expand Down
1 change: 1 addition & 0 deletions lib/best_in_place/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def bip_area(model, attr, new_value)
execute_script <<-JS
$("##{id} form textarea").val('#{escape_javascript new_value.to_s}');
$("##{id} form textarea").blur();
$("##{id} form").submit();
JS
wait_for_ajax
end
Expand Down