From f083807ef67bf486717ac0d7f4fe8358d4d37dfd Mon Sep 17 00:00:00 2001 From: morpheus65535 <5130500+morpheus65535@users.noreply.github.com> Date: Wed, 2 May 2018 06:38:57 -0400 Subject: [PATCH] Settings form validation reworked --- views/settings.tpl | 86 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 16 deletions(-) diff --git a/views/settings.tpl b/views/settings.tpl index 537b87a38..70fd646ca 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -801,30 +801,84 @@ $('#settings_form') .form({ fields: { - settings_general_ip : ['regExp[/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/]', 'empty'], - settings_general_port : ['integer[1..65535]', 'empty'], - - settings_sonarr_ip : ['empty'], - settings_sonarr_port : ['integer[1..65535]', 'empty'], - settings_sonarr_apikey : ['exactLength[32]', 'empty'], - - settings_subliminal_providers : ['minCount[1]', 'empty'], - settings_subliminal_languages : ['minCount[1]', 'empty'] + settings_general_ip : { + rules : [ + { + type : 'regExp[/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/]' + }, + { + type : 'empty' + } + ] + }, + settings_general_port : { + rules : [ + { + type : 'integer[1..65535]' + }, + { + type : 'empty' + } + ] + }, + settings_sonarr_ip : { + rules : [ + { + type : 'empty' + } + ] + }, + settings_sonarr_port : { + rules : [ + { + type : 'integer[1..65535]' + }, + { + type : 'empty' + } + ] + }, + settings_sonarr_apikey : { + rules : [ + { + type : 'exactLength[32]' + }, + { + type : 'empty' + } + ] + }, + settings_subliminal_providers : { + rules : [ + { + type : 'minCount[1]' + }, + { + type : 'empty' + } + ] + }, + settings_subliminal_languages : { + rules : [ + { + type : 'minCount[1]' + }, + { + type : 'empty' + } + ] + } }, inline : true, on : 'blur', - onValid: function(){ - $('#form_validation_error').hide(); - $('.submit').removeClass('disabled'); - }, - onInvalid: function(){ + onFailure: function(){ $('#form_validation_error').show(); $('.submit').addClass('disabled'); - }, - onFailure: function(){ return false; }, onSuccess: function(){ + $('#form_validation_error').hide(); + $('.submit').removeClass('disabled'); $('#loader').addClass('active'); } })