Browse Source

Follow up fix for issue #1952 - New ticket attributes is also show for customers (which should not).

Martin Edenhofer 7 years ago
parent
commit
7fac7501f7

+ 3 - 3
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'

+ 89 - 0
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('<hr><h1>object manager 3</h1><form id="form13"></form>')
+  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')
+
+});