cancel
Showing results for 
Search instead for 
Did you mean: 

Web Form - Required Child Elements in Optional Parent

buck_99
Champ in-the-making
Champ in-the-making
Hi.

I have a parent element that is not required.  Iff the parent element is present, then one of its children is required.  Alfresco won't allow me to get past to step 3 of the Create Web Content wizard because I am leaving the required child field empty, although it is my intention to leave the whole parent empty. 

Thoughts?

- Scott

Here is the schema.  Relevant sections have been highlighted:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:bc="http://www.alfresco.org/alfresco/bc"
           targetNamespace="http://www.alfresco.org/alfresco/bc"
           elementFormDefault="qualified">

  <!– Department –>
  <xs:simpleType name="department">
    <xs:restriction base="xs:normalizedString">
      <xs:enumeration value="Accounts Payable"/>
      <xs:enumeration value="Communications"/>
      <xs:enumeration value="Finance"/>
      <xs:enumeration value="Human Resources"/>
      <xs:enumeration value="IT and Help Desk"/>
      <xs:enumeration value="Payroll"/>
      <xs:enumeration value="Purchasing"/>
      <xs:enumeration value="Records and Archives"/>
      <xs:enumeration value="Travel"/>
    </xs:restriction>
  </xs:simpleType>

  <!– Category –>
  <xs:simpleType name="category">
    <xs:restriction base="xs:normalizedString">
      <xs:enumeration value="Mission"/>
      <xs:enumeration value="Contact"/>
      <xs:enumeration value="Announcement"/>
      <xs:enumeration value="Upcoming Event"/>
    </xs:restriction>
  </xs:simpleType>
 
  <!– Image Size –>
  <xs:simpleType name="size">
    <xs:restriction base="xs:normalizedString">
      <xs:enumeration value="Small"/>
      <xs:enumeration value="Medium"/>
      <xs:enumeration value="Large"/>
    </xs:restriction>
  </xs:simpleType>
 
  <!– Image Alignment –>
  <xs:simpleType name="alignment">
    <xs:restriction base="xs:normalizedString">
      <xs:enumeration value="Left"/>
      <xs:enumeration value="Center"/>
      <xs:enumeration value="Right"/>
    </xs:restriction>
  </xs:simpleType>
 
  <!– News body section:  repeatable element –>
  <xs:complexType name="section">
    <xs:sequence>
      <xs:element name="image" type="bc:image" nillable="true"/> <!– also tried minOccurs="0" maxOccurs="1" –>
      <xs:element name="text" type="xs:string" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>
 
  <!– Image info:  file location, size, and alignment –>
  <xs:complexType name="image">
     <xs:sequence>
        <xs:element name="file" type="xs:normalizedString" minOccurs="1" maxOccurs="1"/> <!– Child element: required if parent exists –>
        <xs:element name="size" type="bc:size" default="Small" minOccurs="1" maxOccurs="1"/>
        <xs:element name="alignment" type="bc:alignment" default="Left" minOccurs="1" maxOccurs="1"/>
     </xs:sequence>
  </xs:complexType>
 
  <!– defines the form for creating a news story –>
  <xs:element name="basic-content">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="title" type="xs:normalizedString" minOccurs="1" maxOccurs="1"/>
        <xs:element name="abstract" type="xs:normalizedString" minOccurs="1" maxOccurs="1"/>
        <xs:element name="date_added" type="xs:date"/> <!– How to put current date as default? –>
        <xs:element name="bodySection" type="bc:section" minOccurs="1" maxOccurs="unbounded"/>
        <xs:element name="keywords" type="xs:normalizedString" minOccurs="0" maxOccurs="1"/>
      <xs:element name="department" type="bc:department" default="HHMI Company-wide"/>
      <xs:element name="category" type="bc:category"/>
      <xs:element name="launch_date" type="xs:date" minOccurs="0" maxOccurs="1"/>
      <xs:element name="expiration_date" type="xs:date" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
2 REPLIES 2

steventux
Champ in-the-making
Champ in-the-making
I'm having similar issues, (excuse the mess) this does allow me to add an image and the copyright be validated or remove the image and the copyright is no longer mandatory.
<!– Body / Bodies –>
            <xs:element name="body" minOccurs="1" maxOccurs="unbounded">
               <xs:complexType>
                  <xs:sequence>
                     <!– Body Text –>
                     <xs:element name="text" type="xs:string" minOccurs="0">
                        <xs:annotation><xs:appinfo><alf:appearance>custom</alf:appearance></xs:appinfo></xs:annotation>
                     </xs:element>
                     <!– Inline Media - Images, Videos –>
                     <xs:element name="media" minOccurs="0" maxOccurs="3">
                        <xs:complexType>
                           <xs:sequence>
                              <!– Image –>
                                <xs:element name="image" minOccurs="0">
                                   <xs:complexType>
                                    <xs:sequence>
                                       <xs:element name="file" type="xs:anyURI" minOccurs="0">
                                          <xs:annotation><xs:appinfo><alf:appearance>folder_restricted_image_picker</alf:appearance></xs:appinfo></xs:annotation>
                                       </xs:element>
                                       <xs:element name="alt_text" type="xs:normalizedString" minOccurs="0" maxOccurs="1"/>
                                    </xs:sequence>
                                 </xs:complexType>
                              </xs:element>
                              <!– Video –>
                              <xs:element name="video" minOccurs="0">
                                 <xs:complexType>
                                    <xs:sequence>
                                       <xs:element name="file" type="xs:anyURI" minOccurs="0">
                                          <xs:annotation><xs:appinfo><alf:appearance>folder_restricted_video_picker</alf:appearance></xs:appinfo></xs:annotation>
                                       </xs:element>
                                    </xs:sequence>
                                 </xs:complexType>
                              </xs:element>
                              <!– Caption and mandatory copyright –>
                              <xs:element name="caption" type="xs:normalizedString" minOccurs="0"/>
                              <xs:element name="copyright" type="xs:normalizedString" minOccurs="1"/>
                              <xs:element name="align" type="art:align" minOccurs="0">                                                                                                                   <xs:annotation><xs:appinfo><alf:appearance>compact</alf:appearance></xs:appinfo></xs:annotation>
                              </xs:element>
                           </xs:sequence>
                        </xs:complexType>
                     </xs:element>
                     <!– Inline Quote block –>
                     <xs:element name="quote" minOccurs="0" maxOccurs="1">
                        <xs:complexType>
                           <xs:sequence>
                              <xs:element name="text" minOccurs="0">
                                   <xs:annotation><xs:appinfo><alf:appearance>small</alf:appearance></xs:appinfo></xs:annotation>
                                   <xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="150"/></xs:restriction></xs:simpleType>
                                </xs:element>
                                <xs:element name="credit" type="xs:normalizedString" minOccurs="0"/>
                                <xs:element name="info" type="xs:normalizedString" minOccurs="0"/>
                             </xs:sequence>
                          </xs:complexType>
                       </xs:element>
                  </xs:sequence>
               </xs:complexType>
            </xs:element>

On a more general note - I'm having trouble predicting how my XForms schema will behave and can't find any meaningful documentation that lets me have the control I need over the output. Given Alfresco WCM relies heavily on Javascript driven widgets, is it necessary to use XForms to create content? Can I build my own input screens easily? Some of the XForms functionality is great straight out-of-the-box but some much-needed functionality seems to be impossible to implement, i.e. Conditional fields and validation.

samwise
Champ in-the-making
Champ in-the-making
I'm experiencing the same error.

When setting minOccurs="0" maxOccurs="1", I would expect the web form to render a contracted, empty element - the same as it would by default when displaying a form for an element with minOccurs="0" maxOccurs="<anything greater than 1>".  Entering content for the one optional instance would be performed by clicking the + button.