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

Add method option to allow for POST requests #537

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Options:
- **:as** It can be only [:input, :textarea, :select, :checkbox, :date] or if undefined it defaults to :input.
- **:collection**: If you are using the :select type then you must specify the collection of values it takes as a hash where values represent the display text and keys are the option's value when selected. If you are using the :checkbox type you can specify the two values it can take, or otherwise they will default to Yes and No.
- **:url**: URL to which the updating action will be sent. If not defined it defaults to the :object path.
- **:method**: HTTP method to be used for the request. Defaults to :put
- **:place_holder**: The nil param defines the content displayed in case no value is defined for that field. It can be something like "click me to edit".
If not defined it will show *"-"*.
- **:activator**: Is the DOM object that can activate the field. If not defined the user will making editable by clicking on it.
Expand Down
6 changes: 4 additions & 2 deletions lib/assets/javascripts/best_in_place.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ BestInPlaceEditor.prototype = {
}

editor.ajax({
"type": BestInPlaceEditor.defaults.ajaxMethod,
"type": this.ajaxMethod,
"dataType": BestInPlaceEditor.defaults.ajaxDataType,
"data": editor.requestData(),
"success": function (data, status, xhr) {
Expand Down Expand Up @@ -169,6 +169,7 @@ BestInPlaceEditor.prototype = {
self.element.parents().each(function () {
var $parent = jQuery(this);
self.url = self.url || $parent.data("bipUrl");
self.ajaxMethod = self.ajaxMethod || $parent.data("bipMethod");
self.activator = self.activator || $parent.data("bipActivator");
self.okButton = self.okButton || $parent.data("bipOkButton");
self.okButtonClass = self.okButtonClass || $parent.data("bipOkButtonClass");
Expand All @@ -179,6 +180,7 @@ BestInPlaceEditor.prototype = {

// Load own attributes (overrides all others)
self.url = self.element.data("bipUrl") || self.url || document.location.pathname;
self.ajaxMethod = self.element.data("bipMethod") || BestInPlaceEditor.defaults.ajaxMethod;
self.collection = self.element.data("bipCollection") || self.collection;
self.formType = self.element.data("bipType") || "input";
self.objectName = self.element.data("bipObject") || self.objectName;
Expand Down Expand Up @@ -253,7 +255,7 @@ BestInPlaceEditor.prototype = {
var csrf_token = jQuery('meta[name=csrf-token]').attr('content'),
csrf_param = jQuery('meta[name=csrf-param]').attr('content');

var data = "_method=" + BestInPlaceEditor.defaults.ajaxMethod;
var data = "_method=" + this.ajaxMethod;
data += "&" + this.objectName + '[' + this.attributeName + ']=' + encodeURIComponent(this.getValue());

if (csrf_param !== undefined && csrf_token !== undefined) {
Expand Down
1 change: 1 addition & 0 deletions lib/best_in_place/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def best_in_place(object, field, opts = {})
options[:data]['bip-skip-blur'] = opts.has_key?(:skip_blur) ? opts[:skip_blur].presence : BestInPlace.skip_blur

options[:data]['bip-url'] = url_for(opts[:url] || object)
options[:data]['bip-method'] = opts[:method] unless opts[:method].blank?

options[:data]['bip-confirm'] = opts[:confirm].presence
options[:data]['bip-value'] = html_escape(value).presence
Expand Down