Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Programmatically activating and deactivating formfields in a group.  (Read 6861 times)
Ben R.
Posts: 28

« on: March 11, 2014, 06:44:53 pm »

Since there is not a built-in function to allow deactivating a group of screen elements, I wrote one. The idea is to pass the group name and active value to a function, which then uses the DOM to cycle through the formfields and update the active attribute accordingly. The reason for wanting to do this is, for example, when adding a customer to the database if we want to capture both a billing and shipment address but want to default to the two being identical, a "Same as shipping" checkbox controls whether the billing address fields are accessible.

Here is an example of the call:

call activate_group("Remit Address", 0)

And here is the function:

  function activate_group(groupName, activeValue)
      groupName string,
      dnForm om.domNode,
      itemList om.nodeList,
      item om.domNode,
      n integer,
      activeValue integer

    let dnForm = ui.interface.getRootNode()
    let itemList = dnForm.selectByTagName("Group")

    for n = 1 to itemList.getlength() #Get list of groups.
      let item = itemList.item(n)
      if item.getattribute("text") = groupName then #Find specified group.
        let item = item.getfirstchild() #Grab first child.

        while item is not null #Loop through group children.
          if item.getattribute("active") is not null then #Verify field has active property.
            call item.setattribute("active", activeValue) #Set property.
          end if
          let item = item.getnext()
        end while

      end if
    end for

  call ui.interface.refresh()
  end function

The problem I'm having is that, although tossing in "display item.getattribute("xxx") shows that the correct values are being retrieved and looped through, "call item.setattribute("xxx", value) doesn't seem to hold. If I loop through with ("active", 0), ("value", "xxx"), or anything else the changes just dissappear. If I trigger the change and then click in the fields, the affected fields flash the appropriate value or flash grey to indicate inactive, but then immediately lose their newly-assigned values.

Any thoughts on the problem here?
Reuben B.
Four Js
Posts: 1010

« Reply #1 on: March 11, 2014, 08:33:26 pm »

Use built-in Genero methods where possible.  So replace

call item.setattribute("active", activeValue)

... with something like ...

d.setFieldActive( item.getAttribute("name"), activeValue)

where d is of type ui.Dialog, and has been populated with a LET d = ui.Dialog.getCurrent() before the loop


Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of
Contributor to
Ben R.
Posts: 28

« Reply #2 on: March 20, 2014, 03:39:09 pm »

Hm. That required a slightly different approach, but worked. Thanks.
Pages: [1]
  Reply  |  Print  
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines