add model and javascript validations for accounts

fixes CNVS-3047

testing steps:
- create a new account
- edit the account and remove the "Account Name"
  try to save and verify an error displays
- edit the account name and make it longer than 255
  and verify it displays it is too long

Change-Id: I9437a16ea5f897a7ee214dcdb3b453599f99c1f7
Reviewed-on: https://gerrit.instructure.com/23465
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jon Jensen <jon@instructure.com>
Reviewed-by: Landon Wilkins <lwilkins@instructure.com>
Product-Review: Marc LeGendre <marc@instructure.com>
QA-Review: Marc LeGendre <marc@instructure.com>
This commit is contained in:
Mark Ericksen 2013-08-19 11:36:53 -06:00
parent b2e44eb237
commit 314e1423a4
2 changed files with 15 additions and 0 deletions

View File

@ -96,6 +96,7 @@ class Account < ActiveRecord::Base
time_zone_attribute :default_time_zone, default: "America/Denver"
validates_locale :default_locale, :allow_nil => true
validates_length_of :name, :maximum => maximum_string_length, :allow_blank => true
validate :account_chain_loop, :if => :parent_account_id_changed?
validate :validate_auth_discovery_url

View File

@ -17,6 +17,7 @@ define([
$(document).ready(function() {
$("#account_settings").submit(function() {
var $this = $(this);
$(".ip_filter .value").each(function() {
$(this).removeAttr('name');
}).filter(":not(.blank)").each(function() {
@ -25,6 +26,19 @@ define([
$(this).attr('name', 'account[ip_filters][' + name + ']');
}
});
var validations = {
object_name: 'account',
required: ['name'],
property_validations: {
'name': function(value){
if (value && value.length > 255) { return I18n.t("account_name_too_long", "Account Name is too long")}
}
}
};
var result = $this.validateForm(validations);
if(!result) {
return false;
}
});
$(".datetime_field").datetime_field();
$("#add_notification_form textarea").editorBox().width('100%');