Improved date and datetime validation.
This commit is contained in:
parent
763964ded1
commit
73f265859d
3 changed files with 10 additions and 8 deletions
|
@ -2367,7 +2367,7 @@ class App.ControllerForm extends App.Controller
|
||||||
throw "Invalid Date #{year}-#{format(month)}-#{format(day)}"
|
throw "Invalid Date #{year}-#{format(month)}-#{format(day)}"
|
||||||
param[ namespace[0] ] = "#{time.getUTCFullYear()}-#{format(time.getUTCMonth()+1)}-#{format(time.getUTCDate())}"
|
param[ namespace[0] ] = "#{time.getUTCFullYear()}-#{format(time.getUTCMonth()+1)}-#{format(time.getUTCDate())}"
|
||||||
catch err
|
catch err
|
||||||
param[ namespace[0] ] = null
|
param[ namespace[0] ] = 'invalid'
|
||||||
console.log('ERR', err)
|
console.log('ERR', err)
|
||||||
else
|
else
|
||||||
param[ namespace[0] ] = undefined
|
param[ namespace[0] ] = undefined
|
||||||
|
@ -2405,7 +2405,7 @@ class App.ControllerForm extends App.Controller
|
||||||
time.setMinutes( time.getMinutes() + time.getTimezoneOffset() )
|
time.setMinutes( time.getMinutes() + time.getTimezoneOffset() )
|
||||||
param[ namespace[0] ] = time.toISOString()
|
param[ namespace[0] ] = time.toISOString()
|
||||||
catch err
|
catch err
|
||||||
param[ namespace[0] ] = null
|
param[ namespace[0] ] = 'invalid'
|
||||||
console.log('ERR', err)
|
console.log('ERR', err)
|
||||||
else
|
else
|
||||||
param[ namespace[0] ] = undefined
|
param[ namespace[0] ] = undefined
|
||||||
|
|
|
@ -139,13 +139,15 @@ class App.Model extends Spine.Model
|
||||||
errors["#{attributeName}_confirm"] = ''
|
errors["#{attributeName}_confirm"] = ''
|
||||||
|
|
||||||
# check datetime
|
# check datetime
|
||||||
if attribute.tag is 'datetime' && data['params'][attributeName] is null
|
if attribute.tag is 'datetime'
|
||||||
|
if data['params'][attributeName] is 'invalid'
|
||||||
errors[attributeName] = 'invalid'
|
errors[attributeName] = 'invalid'
|
||||||
|
|
||||||
# validate value
|
# validate value
|
||||||
|
|
||||||
# check date
|
# check date
|
||||||
if attribute.tag is 'date' && data['params'][attributeName] is null
|
if attribute.tag is 'date'
|
||||||
|
if data['params'][attributeName] is 'invalid'
|
||||||
errors[attributeName] = 'invalid'
|
errors[attributeName] = 'invalid'
|
||||||
|
|
||||||
# validate value
|
# validate value
|
||||||
|
|
|
@ -243,14 +243,14 @@ test( "date validation check", function() {
|
||||||
// check params
|
// check params
|
||||||
params = App.ControllerForm.params( el )
|
params = App.ControllerForm.params( el )
|
||||||
test_params = {
|
test_params = {
|
||||||
date1: null,
|
date1: 'invalid',
|
||||||
}
|
}
|
||||||
deepEqual( params, test_params, 'params check' )
|
deepEqual( params, test_params, 'params check' )
|
||||||
|
|
||||||
// check errors
|
// check errors
|
||||||
errors = form.validate(params)
|
errors = form.validate(params)
|
||||||
test_errors = {
|
test_errors = {
|
||||||
date1: "invalid",
|
date1: 'invalid',
|
||||||
}
|
}
|
||||||
deepEqual( errors, test_errors, 'validation errors check' )
|
deepEqual( errors, test_errors, 'validation errors check' )
|
||||||
App.ControllerForm.validate( { errors: errors, form: el } )
|
App.ControllerForm.validate( { errors: errors, form: el } )
|
||||||
|
|
Loading…
Reference in a new issue