Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to show combobox display value

    Suppose I have a data source for products that has the field supplier_id. When opening the form for an existing product, I want to see the name of the supplier. I want to send this name from the server together with this ID (so that no extra query is necessary to retrieve the supplier). Therefore I use a SQL statement like this:

    Code:
      SELECT     products.id,
                 products.supplier_id,
                 suppliers.name AS supplier_name
      FROM       products
      INNER JOIN suppliers ON suppliers.id = products.supplier_id
    To change the supplier, I show a combo box and only then a query needs to be done to retrieve the suppliers. On the server it should be a SQL like:

    Code:
      SELECT id,
             name
      FROM   suppliers
    I was hoping to be able to do something like this (like in a ListGrid):

    Code:
      isc.DynamicForm.create({
        fields: [
          { name: 'supplier_id', displayField: 'supplier_name' }
        ]
      });
    And then I need to specify different values for displayField and valueField when the combo box is pressed.

    I don't think this is possible, so I'm looking for a suitable "work-around" / solution. I've also tried to do something with setting the foreignKey property on the supplier_id field in the data source of products. This causes an extra query, which is not that big of a deal, but I have an extra issue there. In reality all my records have a field "shop_code" indicating the shop the product belongs to (so one database is used for multiple shops). So when retrieving the supplier, it also needs to send the shop_code of the product (which is the same). My SQL statement in fact needs to be something like this:

    Code:
      SELECT     products.id,
                 products.supplier_id,
                 suppliers.name AS supplier_name
      FROM       products
      INNER JOIN suppliers ON suppliers.id = products.supplier_id AND suppliers.shop_code = products.shop_code
    I don't know where or when to specify this extra request parameter (if possible at all). It basically means I have a composed foreign key relation and reading the Quick Start Guide gives me the feeling this is not possible.
    Last edited by wallytax; 18 Jun 2015, 23:34.

    #2
    Although I still have issues figuring out what the best way is to work with combo boxes for suppliers, I do have one question in particular.

    When I open an existing product it will fire a request to get the current supplier. I'm doing some trickery to convert the url the data source will use on a per-request base. For this trickery it is necessary that I set a value on the request object before have the suppliers data source performing an request. Is this possible and if so where?

    Some background: my product record has a field "shop_code" that needs to be passed to the request object before requesting a supplier (both need to be records of the same shop).

    Any help will very much be appreciated.

    Comment


      #3
      For people interested in knowing a solution: I found the right property and it is "optionCriteria". Each form in my application is specific for a shop, so I instantiate them with a property "shop_code". Based on that, I created the following component:

      Code:
          // custom form item class for combo box properties (for my application)
          isc.defineClass('MyComboBoxItem', isc.ComboBoxItem).addProperties({
              addUnknownValues: false,
              cachePickListResults: false,
              displayField: 'name',
              minimumSearchLength: 2,
              valueField: 'id',
      
              init: function () {
                  this.optionCriteria = isc.addProperties({
                      site_code: this.form.shop_code
                  }, this.optionCriteria);
                  this.Super('init', arguments);
              }
          });
      
          // the form defines a combo box as follows:
          var form = isc.DynamicForm.create({
              fields: [
                  { name: 'supplier_id', editorType: 'myComboBox', optionsDataSource: 'suppliers' }
              ]
          });
      In my custom DataSource class I perform some trickery in the getDataURL() method to create an URL with the shop code in it (thus not as query string parameter) but this is up to you.

      Comment

      Working...
      X