Skip to content
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
23 changes: 19 additions & 4 deletions lib/assets/javascripts/best_in_place.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ BestInPlaceEditor.prototype = {
if (self.formType === "select" || self.formType === "checkbox") {
self.values = self.collection;
self.collectionValue = self.element.data("bipValue") || self.collectionValue;
} else if (self.formType === "input") {
if (self.html_attrs != null && self.html_attrs["type"] != null) {
self.input_type = self.html_attrs["type"];
} else {
self.input_type = "text";
}
}
},

Expand Down Expand Up @@ -371,7 +377,7 @@ BestInPlaceEditor.forms = {
.attr('action', 'javascript:void(0);')
.attr('style', 'display:inline');
var input_elt = jQuery(document.createElement('input'))
.attr('type', 'text')
.attr('type', this.input_type)
.attr('name', this.attributeName)
.val(this.display_value);

Expand All @@ -386,15 +392,15 @@ BestInPlaceEditor.forms = {
this.element.html(output);
this.setHtmlAttributes();

this.element.find("input[type='text']")[0].select();
this.element.find("input[type='" + this.input_type + "']")[0].select();
this.element.find("form").bind('submit', {editor: this}, BestInPlaceEditor.forms.input.submitHandler);
if (this.cancelButton) {
this.element.find("input[type='button']").bind('click', {editor: this}, BestInPlaceEditor.forms.input.cancelButtonHandler);
}
if (!this.okButton) {
this.element.find("input[type='text']").bind('blur', {editor: this}, BestInPlaceEditor.forms.input.inputBlurHandler);
this.element.find("input[type='" + this.input_type + "']").bind('blur', {editor: this}, BestInPlaceEditor.forms.input.inputBlurHandler);
}
this.element.find("input[type='text']").bind('keyup', {editor: this}, BestInPlaceEditor.forms.input.keyupHandler);
this.element.find("input[type='" + this.input_type + "']").bind('keyup', {editor: this}, BestInPlaceEditor.forms.input.keyupHandler);
this.blurTimer = null;
this.userClicked = false;
},
Expand All @@ -407,6 +413,15 @@ BestInPlaceEditor.forms = {
// When buttons are present, use a timer on the blur event to give precedence to clicks
inputBlurHandler: function (event) {
'use strict';
// Checking if input value is valid (native html5 validation)
// If browser doesn't supports html5 validation willValidate property will be 'undefined' and
// no check will be performed
var input = event.data.editor.element.find("input[type='" + event.data.editor.input_type + "']").get(0);
if (input.willValidate == true && !input.validity.valid) {
event.data.editor.abort();
return;
}

if (event.data.editor.okButton) {
event.data.editor.blurTimer = setTimeout(function () {
if (!event.data.editor.userClicked) {
Expand Down
2 changes: 1 addition & 1 deletion lib/best_in_place/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def finished_all_ajax_requests?
evaluate_script('!window.jQuery') || evaluate_script('jQuery.active').zero?
end

def wait_until(max_execution_time_in_seconds = Capybara.default_wait_time)
def wait_until(max_execution_time_in_seconds = Capybara.default_max_wait_time)
Timeout.timeout(max_execution_time_in_seconds) do
loop do
if yield
Expand Down
4 changes: 4 additions & 0 deletions spec/internal/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
*= require_self
*= require_tree .
*/
2 changes: 1 addition & 1 deletion spec/internal/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>Best In Place TEST APP <%= Rails::VERSION::STRING %></title>
<%= stylesheet_link_tag "scaffold", "style", "jquery-ui-1.8.16.custom" %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tag %>
</head>
Expand Down