Merge pull request #165 from mz3944/mz_replace_hardcoded_values_with_constants_v2

Added missing validation for protocol description.
This commit is contained in:
mz3944 2016-09-22 17:36:18 +02:00 committed by GitHub
commit cde7f3805f
3 changed files with 9 additions and 23 deletions

View file

@ -20,13 +20,7 @@ $("form#new_custom_field").on("ajax:success", function(ev, data, status) {
});
$("form#new_custom_field").on("ajax:error", function(e, data, status, xhr) {
input = $(this).find("#name-input");
input.closest(".form-group").find(".help-block").remove();
input.closest(".form-group").addClass("has-error");
$.each(data.responseJSON, function(i, val) {
input.parent().append("<span class='help-block'>" + val[0].charAt(0).toUpperCase() + val[0].slice(1) +"<br /></span>");
});
$('form').renderFormErrors('custom_field', data.responseJSON, true, e);
});
// Create sample type ajax
@ -51,13 +45,7 @@ $("form#new_sample_type").on("ajax:success", function(ev, data, status) {
});
$("form#new_sample_type").on("ajax:error", function(e, data, status, xhr) {
input = $(this).find("#name-input");
input.closest(".form-group").find(".help-block").remove();
input.closest(".form-group").addClass("has-error");
$.each(data.responseJSON, function(i, val) {
input.parent().append("<span class='help-block'>" + val[0].charAt(0).toUpperCase() + val[0].slice(1) +"<br /></span>");
});
$('form').renderFormErrors('sample_type', data.responseJSON, true, e);
});
// Create sample group ajax
@ -82,13 +70,7 @@ $("form#new_sample_group").on("ajax:success", function(ev, data, status) {
});
$("form#new_sample_group").on("ajax:error", function(e, data, status, xhr) {
input = $(this).find("#name-input");
input.closest(".form-group").find(".help-block").remove();
input.closest(".form-group").addClass("has-error");
$.each(data.responseJSON, function(i, val) {
input.parent().append("<span class='help-block'>" + val[0].charAt(0).toUpperCase() + val[0].slice(1) +"<br /></span>");
});
$('form').renderFormErrors('sample_group', data.responseJSON, true, e);
});

View file

@ -20,7 +20,10 @@ class CustomFieldsController < ApplicationController
},
status: :ok }
else
format.json { render json: @custom_field.errors, status: :unprocessable_entity }
format.json do
render json: @custom_field.errors.to_json,
status: :unprocessable_entity
end
end
end
end

View file

@ -13,9 +13,10 @@ class Protocol < ActiveRecord::Base
in_repository_archived: 4
}
auto_strip_attributes :name, nullify: false
auto_strip_attributes :name, :description, nullify: false
# Name is required when its actually specified (i.e. :in_repository? is true)
validates :name, length: { maximum: NAME_MAX_LENGTH }
validates :description, length: { maximum: TEXT_MAX_LENGTH }
validates :organization, presence: true
validates :protocol_type, presence: true