Expand my Community achievements bar.

SOLVED

Schema for drop down lists (with name/value pairs)

Avatar

Level 1

Hi,

I am looking for information on creating a schema type definition that LiveCycle Designer ES will accept for populating drop down lists ( populating both the name and the value). For example, I have something like:

    <xsd:simpleType name="RoleTypeCodeType">
     <xsd:restriction base="xsd:token">
      <xsd:enumeration value="ABC">
       <xsd:annotation>
        <xsd:documentation>
         Aboriginal Community
        </xsd:documentation>
       </xsd:annotation>
      </xsd:enumeration>
      <xsd:enumeration value="ADJ">
       <xsd:annotation>
        <xsd:documentation>Adjudicator</xsd:documentation>
       </xsd:annotation>
      </xsd:enumeration>
...

      <xsd:minLength value="1"></xsd:minLength>
      <xsd:maxLength value="3"></xsd:maxLength>
     </xsd:restriction>
    </xsd:simpleType>

that creates a list. I can bind this to a list field. However, of course, when I preview the pdf, my pull down list items in this field are just the three letter codes. I would like to get the associated descriptions for these items (as shown on the binding tab) to be populated. The end result is that my list would display "Aboriginal Community","Adjudicator" etc and when selected, return "ABC","ADJ" into the xml when exported.

If the list items on the binding tab are manually populated then this export works correctly. However, the list is dynamic and generated at runtime. So, does anyone know what the schema definition should be for the list field on the LiveCycle form to create the name-value pairs?

thanks,

John

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi John,

You will have to embed the schema, but you can reference the imported schema as they will get embedded as well (There was a bug in Designer when they were not embedded but I think this got fixed in 8.0).

Anyway to reference the imported schema you will have to loop though all schemas so;

var

schemas = xfa.resolveNodes('schema[*]');

Will give you reference to all the schemas, the loop though them;

for

(var schemaIndex = 0; schemaIndex < schemas.length; schemaIndex++)

Then if the schemas have an id attribute (I don't think you can reference any namespace attributes) test for the id value;

if

(schema.@id == 'whateveryourschemaidis')

If there is no id attribute and you can't add one then you might have to look for the type in each schema, something like;

var roleTypeCodeType = schema.xsd::simpleType.(@name == 'roleTypeCodeType');

if (roleTypeCodeType !== undefined)

{

     ... load annotation values.

}

Hope that helps but if you if you can post your schema (and it's imports) then I might understand exactly the problem.

Bruce

View solution in original post

8 Replies

Avatar

Level 10

Hi John,

I've not had any joy coding against the schema within an form using the normal sort of javascript references. 

But you can do what you want with some E4X (which came in with Reader 8.0).

So in the initialise event of the dropdown list you could have some code like;

// remove XML Declaration

var schema = new XML(xfa.schema.saveXML('pretty').replace(/<.*>/,''));


// define xsd namespace

var xsd = Namespace('http://www.w3.org/2001/XMLSchema')


// assume the type we are after is global

var roleTypeCodeType = schema.xsd::simpleType.(@name = 'RoleTypeCodeType');


// load up each restriction element

for each (elm in roleTypeCodeType.xsd::restriction.xsd::enumeration)

{

   RoleTypeCode.addItem(elm.xsd::annotation.xsd::documentation.toString(), elm.@value.toString());

}

This reads the schema (you will have to embed it in the form) and then processes it as if it was any other XML.

See attach form I used to test the above code.

Bruce

Avatar

Former Community Member

There are additional properties that you can bind to in an object. They are not visisble by default. To turn them on highlight the DDlist that you want to bind to and look at the Object palette. In the top right corner of the palette is an icon that brings up a menu (see the image below):

Capture.GIF

Choose the "Show Dynamic Properties option. Any property that can be bound will be highlighted and underlined as a link. Click on the property you want to bind and a binding dialogue will appear. In your case choose the List Items property (see the image below:

Capture.GIF

Now you can set your bindings for Text and Value through that dialog.

Paul

Avatar

Level 1

Hi Bruce,

thanks very much for your reply. It does work well. However, I was wondering about two things.

Your solution has a requirement to embed the schema into the pdf. Can I get this solution to work without embedding the schema?

I have not worked with schemas too much, but I think the values for the list are not global for the schema I was given. I am attaching a schema in designer, however at the top of the schema are a couple import statements:

<xsd:import schemaLocation="../../base/1.0/CourtDocumentBase.xsd"
  namespace="http://courtservices.bc.ca/xmlschemas/forms/base/1.0"></xsd:import>
<xsd:import schemaLocation="../../ext/1.0/CourtDocumentExtensions.xsd"
  namespace="http://courtservices.bc.ca/xmlschemas/forms/ext/1.0"></xsd:import>

that have the code branch for the RoleTypeCodeType shown previously. Is there a way to reference the RoleTypeCode when it is in another xsd file? Or should it be found with the example you provided? The problem I am having is that my lists are not populating when I include the import statement.

thanks again for any assistance.

John

Avatar

Level 1

Hi Paul,

when I click on the text or value item selections as shown in your example, I can find the enueration value (which is the three letter code eg ABC), but then the second option is simply 'NONE'. So when I select that, adobe then just puts in its own sequential numeric value, which is not quite what I want. Would there be a way to structure the xml in the schema differently so that LiveCycle sees both the name and the value?

For example, a snippet of the schema I was given looks like:

<xsd:simpleType name="RoleTypeCodeType">
  <xsd:restriction base="xsd:token">
   <xsd:enumeration value="ABC">
    <xsd:annotation>
     <xsd:appinfo>Aboriginal Community</xsd:appinfo>
    </xsd:annotation>
   </xsd:enumeration>
   <xsd:enumeration value="ADJ">
    <xsd:annotation>
     <xsd:appinfo>Adjudicator</xsd:appinfo>
    </xsd:annotation>
   </xsd:enumeration>
...

   <xsd:minLength value="1"></xsd:minLength>
   <xsd:maxLength value="4"></xsd:maxLength>
  </xsd:restriction>
</xsd:simpleType>

thanks for your response previously,

John

Avatar

Former Community Member

Now that I see it I think I may have steered you wrong. I do not know of a way in the schema to carry both values. You can bind the schema value to the Text value of the dropdown, then in the Binding tab you can specify the Value property by clicking on the item and entering the value that you want. probably not ideal....but it is workable. All other times I have doen this I have used data files and nopt schemas. In teh data file case the Value of the DD was a node in the XML and the Text property was an attribute of that node. Thats what the extended dialog was built for.

paul

Avatar

Correct answer by
Level 10

Hi John,

You will have to embed the schema, but you can reference the imported schema as they will get embedded as well (There was a bug in Designer when they were not embedded but I think this got fixed in 8.0).

Anyway to reference the imported schema you will have to loop though all schemas so;

var

schemas = xfa.resolveNodes('schema[*]');

Will give you reference to all the schemas, the loop though them;

for

(var schemaIndex = 0; schemaIndex < schemas.length; schemaIndex++)

Then if the schemas have an id attribute (I don't think you can reference any namespace attributes) test for the id value;

if

(schema.@id == 'whateveryourschemaidis')

If there is no id attribute and you can't add one then you might have to look for the type in each schema, something like;

var roleTypeCodeType = schema.xsd::simpleType.(@name == 'roleTypeCodeType');

if (roleTypeCodeType !== undefined)

{

     ... load annotation values.

}

Hope that helps but if you if you can post your schema (and it's imports) then I might understand exactly the problem.

Bruce

Avatar

Level 1

Hi

for anyone interested in this, I am providing a working example based on previous comments.

var

schemas = xfa.resolveNodes('schema[*]');

var x

sd = Namespace('http://www.w3.org/2001/XMLSchema');

for

(var schemaIndex = 0; schemaIndex < schemas.length; schemaIndex++) {

  // each schema has a schemaId attribute

  if (schemas.item(schemaIndex).getAttribute('schemaId') == 'cdext') {

    // grab a single schema and convert to xml

    var schema = new XML(schemas.item(schemaIndex).saveXML('pretty').replace(/<.*>/,''));

    try {

      var roleTypeCodeType = schema.xsd::simpleType.(@name = 'RoleTypeCodeType');

    }

catch(e) {

      var roleTypeCodeType = undefined;

    }

    if (roleTypeCodeType != undefined) {

      for each (elm in roleTypeCodeType.xsd::restriction.xsd::enumeration) {

        RoleTypeCode.addItem(elm.xsd

::annotation.xsd::appinfo.toString(), elm.@value.toString());

      }

    }

  }

}

based on an imported schema (shemaId='cdext') that looks like:

<xsd:simpleType name="RoleTypeCodeType">

  <xsd:restriction base="xsd:token">

  <xsd:enumeration value="ABC">

    <xsd:annotation>

      <xsd:appinfo>Aboriginal Community</xsd:appinfo>

    </xsd:annotation>

  </xsd:enumeration>

  <xsd:enumeration value="ADJ">

    <xsd:annotation>

      <xsd:appinfo>Adjudicator</xsd:appinfo>

    </xsd:annotation>

  </xsd:enumeration>

</xsd:simpleType>

Remember, I am binding one main schema (schemaId = 'cdmain') that imports several other schemas.

John

Avatar

Level 1

...  I was too quick to post the answer. One bug found:

change:

      var roleTypeCodeType = schema.xsd::simpleType.(@name = 'RoleTypeCodeType');

to:

      var roleTypeCodeType = schema.xsd::simpleType.(@name == 'RoleTypeCodeType');