From 7fac7501f76771f314de3413aa5239ce65953244 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 16 Apr 2018 02:11:17 +0200 Subject: [PATCH] Follow up fix for issue #1952 - New ticket attributes is also show for customers (which should not). --- .../_application_controller_form.coffee | 6 +- public/assets/tests/form.js | 89 +++++++++++++++++++ 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.coffee index 1a8841d32..3fadb2697 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.coffee @@ -466,9 +466,9 @@ class App.ControllerForm extends App.Controller uncheckParam = {} lookupForm.find('input[type=checkbox]').each( (index) -> type = $(@).data('field-type') - checked = $(@).attr('checked') + checked = $(@).prop('checked') name = $(@).attr('name') - if name && !checked && (!(name of param) || param[name] is '') + if name && !checked && !(name of param) if !(name of uncheckParam) if type is 'boolean' uncheckParam[name] = false @@ -482,7 +482,7 @@ class App.ControllerForm extends App.Controller # verify if we have not checked radios lookupForm.find('input[type=radio]').each( (index) -> type = $(@).data('field-type') - checked = $(@).attr('checked') + checked = $(@).prop('checked') name = $(@).attr('name') if name && !checked && !(name of param) if type is 'boolean' diff --git a/public/assets/tests/form.js b/public/assets/tests/form.js index c49ff44f3..eabd55252 100644 --- a/public/assets/tests/form.js +++ b/public/assets/tests/form.js @@ -1176,3 +1176,92 @@ test("object manager form 2", function() { deepEqual(params, test_params, 'form param check') }); + +test("object manager form 3", function() { + + $('#forms').append('

object manager 3

') + var el = $('#form13') + + var defaults = {} + new App.ControllerForm({ + el: el, + model: { + configure_attributes: [ + { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false }, + ], + }, + params: $.extend(defaults, { object: 'Ticket' }), + autofocus: true + }); + + var params = App.ControllerForm.params(el) + var test_params = { + data_option: { + default: "", + maxlength: 120, + type: "text" + }, + data_type: "input", + screens: { + create_middle: { + "ticket.agent": { + shown: true, + required: false, + }, + "ticket.customer": { + shown: true, + required: false, + } + }, + edit: { + "ticket.agent": { + shown: true, + required: false, + }, + "ticket.customer": { + shown: true, + required: false, + } + } + } + } + + deepEqual(params, test_params, 'form param check') + + el.find('[name="screens::create_middle::ticket.customer::shown"]').click() + el.find('[name="screens::edit::ticket.customer::shown"]').click() + + params = App.ControllerForm.params(el) + test_params = { + data_option: { + default: "", + maxlength: 120, + type: "text" + }, + data_type: "input", + screens: { + create_middle: { + "ticket.agent": { + shown: true, + required: false, + }, + "ticket.customer": { + shown: false, + required: false, + } + }, + edit: { + "ticket.agent": { + shown: true, + required: false, + }, + "ticket.customer": { + shown: false, + required: false, + } + } + } + } + deepEqual(params, test_params, 'form param check') + +});