Improved date and datetime validation.

This commit is contained in:
Martin Edenhofer 2015-04-14 07:33:47 +02:00
parent 763964ded1
commit 73f265859d
3 changed files with 10 additions and 8 deletions

View file

@ -2367,7 +2367,7 @@ class App.ControllerForm extends App.Controller
throw "Invalid Date #{year}-#{format(month)}-#{format(day)}"
param[ namespace[0] ] = "#{time.getUTCFullYear()}-#{format(time.getUTCMonth()+1)}-#{format(time.getUTCDate())}"
catch err
param[ namespace[0] ] = null
param[ namespace[0] ] = 'invalid'
console.log('ERR', err)
else
param[ namespace[0] ] = undefined
@ -2405,7 +2405,7 @@ class App.ControllerForm extends App.Controller
time.setMinutes( time.getMinutes() + time.getTimezoneOffset() )
param[ namespace[0] ] = time.toISOString()
catch err
param[ namespace[0] ] = null
param[ namespace[0] ] = 'invalid'
console.log('ERR', err)
else
param[ namespace[0] ] = undefined

View file

@ -139,14 +139,16 @@ class App.Model extends Spine.Model
errors["#{attributeName}_confirm"] = ''
# check datetime
if attribute.tag is 'datetime' && data['params'][attributeName] is null
errors[attributeName] = 'invalid'
if attribute.tag is 'datetime'
if data['params'][attributeName] is 'invalid'
errors[attributeName] = 'invalid'
# validate value
# check date
if attribute.tag is 'date' && data['params'][attributeName] is null
errors[attributeName] = 'invalid'
if attribute.tag is 'date'
if data['params'][attributeName] is 'invalid'
errors[attributeName] = 'invalid'
# validate value

View file

@ -243,14 +243,14 @@ test( "date validation check", function() {
// check params
params = App.ControllerForm.params( el )
test_params = {
date1: null,
date1: 'invalid',
}
deepEqual( params, test_params, 'params check' )
// check errors
errors = form.validate(params)
test_errors = {
date1: "invalid",
date1: 'invalid',
}
deepEqual( errors, test_errors, 'validation errors check' )
App.ControllerForm.validate( { errors: errors, form: el } )