Javascript条件字段(Zendesk Lotus)

时间:2012-12-17 01:24:35

标签: javascript forms conditional field zendesk

我正在尝试配置一些javascript代码以在Zendesk Lotus中创建一个条件字段应用程序。下面是javascipt模板和我当前的html。有人能给我一个例子,说明我将如何更改java模板以适应我的html?当我从第一个下拉列表(ticket_fields_21013678)中选择选项'qa'时,我只想显示第二个下拉表单字段(ticket_fields_21552756)。一旦有人告诉我如何做到这一点,我将能够自己做其余的事情:)

PS,javascript必须保持以下格式

提前感谢您的帮助!

使用Javascript:

    (function(){
  var projectRequest = ['280865'],
      otherHelpesk = ['279466'],
      hideAll = [].concat(projectRequest, otherHelpesk),
      moodFieldMap = {
        cat:[].concat(projectRequest),
        dog:[].concat(otherHelpesk),
        dolphin: [].concat(projectRequest, otherHelpesk)
      };

  return {
    appID:  'https://github.com/zendesk/widgets/tree/master/ConditionalFieldsApp',
    defaultState: 'loading',
    type2thing: '',

    events: {
      'app.activated': 'setValue',
      'ticket.custom_field_21631456.changed': 'typeII'
    }, //end events

    typeII: function(){
      this.hide(hideAll);
      this.type2thing = this.ticket().customField('custom_field_21631456');
      //console.log('control field value: ' + this.type2thing);
      if (this.type2thing != null) {
       this.show(moodFieldMap[this.type2thing]);
      }
    },

    setValue: function() {
      //console.log('activated', arguments);
      this.typeII();
    },

    hide: function(fields){
      fields.forEach(function(field) {
        this.ticketFields('custom_field_' + field).hide();
      }, this);
    },

    show: function(fields) {
      fields.forEach(function(field) {
        this.ticketFields('custom_field_' + field).show();
      }, this);
    }
  };
}());

我的HTML:

<select id="ticket_fields_21013678" name="ticket[fields][21013678]" tabindex="8"><option value="">-</option>
<option value="depreqaccount_management">Account Management</option>
<option value="ce_vp">CE/VP</option>
<option value="city_management">City Management</option>
<option value="city_planning">City Planning</option>
<option value="customer_service">Customer Service</option>
<option value="depreq_images">Images</option>
<option value="partner_management">Partner Management</option>
<option value="production">Production</option>
<option value="qa">QA</option>
<option value="senior_management">Senior Management</option>
<option value="depreq_writers">Writers</option>
<option value="depreq_bdm">BDM</option></select>

<select id="ticket_fields_21552756" name="ticket[fields][21552756]" tabindex="9"><option value="">-</option>
<option value="responsibility_account_manager">Account Manager</option>
<option value="responsibility_bdm">BDM</option>
<option value="responsibility_ce_vp">CE/VP</option>
<option value="responsibility_city_manager">City Manager</option>
<option value="responsibility_city_planner">City Planner</option>
<option value="responsibility_customer_service">Customer Service</option>
<option value="responsibility_image_designer">Images</option>
<option value="responsibility_merchant">Merchant</option>
<option value="responsibility_partner_manager">Partner Manager</option>
<option value="responsibility_producer">Producer</option>
<option value="responsibility_qa">QA</option>
<option value="responsibility_writer">Writer</option></select>

1 个答案:

答案 0 :(得分:1)

您可以在https://github.com/zendesklabs/conditional_fields_app

查看最新版本的Zendesk代理界面