Extended tests for checkbox and radio element.

This commit is contained in:
Martin Edenhofer 2018-02-16 09:08:08 +01:00
parent 506fe55608
commit 347dd95c2f
2 changed files with 67 additions and 22 deletions

View file

@ -454,6 +454,26 @@ class App.ControllerForm extends App.Controller
else else
param[item.name] = value param[item.name] = value
# verify if we have not checked checkboxes
uncheckParam = {}
lookupForm.find('input[type=checkbox]').each( (index) ->
checked = $(@).attr('checked')
name = $(@).attr('name')
if !checked && !param[name] || param[name] is ''
if uncheckParam[name] is ''
uncheckParam[name] = []
else
uncheckParam[name] = ''
)
lookupForm.find('input[type=radio]').each( (index) ->
checked = $(@).attr('checked')
name = $(@).attr('name')
if !checked && !param[name] || param[name] is ''
uncheckParam[name] = ''
)
for key, value of uncheckParam
param[key] = value
# data type conversion # data type conversion
for key of param for key of param

View file

@ -24,6 +24,8 @@ test("form elements check", function() {
selectmultioption2: [ false, true ], selectmultioption2: [ false, true ],
richtext2: 'lalu <l> lalu', richtext2: 'lalu <l> lalu',
datetime1: Date.parse('2015-01-11T12:40:00Z'), datetime1: Date.parse('2015-01-11T12:40:00Z'),
checkbox1: [],
checkbox2: '1',
} }
new App.ControllerForm({ new App.ControllerForm({
el: el, el: el,
@ -45,6 +47,8 @@ test("form elements check", function() {
{ name: 'richtext2', display: 'Richtext2', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext2'] }, { name: 'richtext2', display: 'Richtext2', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext2'] },
{ name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] }, { name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
{ name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: false, default: defaults['datetime2'] }, { name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: false, default: defaults['datetime2'] },
{ name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
{ name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
] ]
}, },
autofocus: true autofocus: true
@ -100,6 +104,10 @@ test("form elements check", function() {
//equal(el.find('[name="richtext2"]').prop('required'), true, 'check textarea2 required') //equal(el.find('[name="richtext2"]').prop('required'), true, 'check textarea2 required')
equal(el.find('[name="richtext2"]').is(":focus"), false, 'check textarea2 focus') equal(el.find('[name="richtext2"]').is(":focus"), false, 'check textarea2 focus')
equal(el.find('[name="checkbox1"]').first().is(":checked"), false)
equal(el.find('[name="checkbox1"]').last().is(":checked"), false)
equal(el.find('[name="checkbox2"]').is(":checked"), true)
}); });
test("form params check", function() { test("form params check", function() {
@ -134,6 +142,11 @@ test("form params check", function() {
date3: '2015-01-11', date3: '2015-01-11',
active1: true, active1: true,
active2: false, active2: false,
checkbox1: [],
checkbox2: '',
checkbox3: 'd',
radiobox1: '',
radiobox2: 'a',
} }
new App.ControllerForm({ new App.ControllerForm({
el: el, el: el,
@ -173,6 +186,12 @@ test("form params check", function() {
{ name: 'date4', display: 'Date4', tag: 'date', null: false, default: defaults['date4'] }, { name: 'date4', display: 'Date4', tag: 'date', null: false, default: defaults['date4'] },
{ name: 'active1', display: 'Active1', tag: 'active', default: defaults['active1'] }, { name: 'active1', display: 'Active1', tag: 'active', default: defaults['active1'] },
{ name: 'active2', display: 'Active2', tag: 'active', default: defaults['active2'] }, { name: 'active2', display: 'Active2', tag: 'active', default: defaults['active2'] },
{ name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
{ name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
{ name: 'checkbox3', display: 'Checkbox3', tag: 'checkbox', null: false, default: defaults['checkbox3'], options: { c: 'CC', d: 'DD' } },
{ name: 'checkbox4', display: 'Checkbox4', tag: 'checkbox', null: false, default: defaults['checkbox4'], options: { aa: 'AA', bb: 'BB' } },
{ name: 'radiobox1', display: 'Radiobox1', tag: 'radio', null: false, default: defaults['radiobox1'], options: { a: 'AA', b: 'BB' } },
{ name: 'radiobox2', display: 'Radiobox2', tag: 'radio', null: false, default: defaults['radiobox2'], options: { a: '11' } },
], ],
}, },
params: defaults, params: defaults,
@ -271,6 +290,12 @@ test("form params check", function() {
date4: undefined, date4: undefined,
active1: true, active1: true,
active2: false, active2: false,
checkbox1: [],
checkbox2: '',
checkbox3: 'd',
checkbox4: [],
radiobox1: '',
radiobox2: 'a',
} }
deepEqual(params, test_params, 'form param check') deepEqual(params, test_params, 'form param check')