<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!--+
    | CForms aggegate sample form definition file.
    |
    | CVS $Id: form.xml 433543 2006-08-22 06:22:54Z crossley $
    +-->

<wd:form xmlns:wd="http://apache.org/cocoon/woody/definition/1.0">
  <wd:widgets>
    <wd:aggregatefield id="phone" required="true">
      <wd:label>
        Enter Phone Number
        <br/><small>(Format is: 999-999-9999x9999)
        <br/>Extension number is optional.</small>
      </wd:label>
      <wd:datatype base="string"/>

      <wd:split pattern="([0-9]{3})-([0-9]{3})-([0-9]{4})(x([0-9]{1,4}))?">
        <wd:map group="1" field="part1"/>
        <wd:map group="2" field="part2"/>
        <wd:map group="3" field="part3"/>
        <wd:map group="5" field="part4"/>
        <wd:failmessage>Not a valid phone number.</wd:failmessage>
      </wd:split>
      <wd:combine expression='Concat(part1, "-", part2, "-", part3, If(IsNull(part4), "", Concat("x", part4))) )'/>

      <wd:widgets>
        <wd:field id="part1" required="true">
          <wd:label>
            Enter Phone (Part1)
            <br/><small>(Format is: 999)</small>
          </wd:label>
          <wd:datatype base="string"/>
        </wd:field>
        <wd:field id="part2" required="true">
          <wd:label>
            Enter Phone (Part2)
            <br/><small>(Format is: 999)</small>
          </wd:label>
          <wd:datatype base="string"/>
        </wd:field>
        <wd:field id="part3" required="true">
          <wd:label>
            Enter Phone (Part3)
            <br/><small>(Format is: 9999)</small>
          </wd:label>
          <wd:datatype base="string"/>
        </wd:field>
        <wd:field id="part4">
          <wd:label>
            Enter Phone (Part4)
            <br/><small>(Format is: 9999)</small>
          </wd:label>
          <wd:datatype base="string"/>
        </wd:field>
      </wd:widgets>
    </wd:aggregatefield>


    <wd:aggregatefield id="date" required="true">
      <wd:label>
        Enter Date
        <br/><small>(Format is: dd/MM/yyyy)
        <br/>Year should be between 1990 and 2010. Day should be between 1 to 15</small>
      </wd:label>
      <wd:datatype base="date">
        <wd:convertor>
          <wd:patterns>
            <wd:pattern>dd/MM/yyyy</wd:pattern>
          </wd:patterns>
        </wd:convertor>
        <wd:validation>
          <wd:range min="Date(1990, 1, 1)" max="Date(2010, 12, 31)">
            <wd:failmessage>Enter date in 1990 to 2010 year</wd:failmessage>
          </wd:range>
        </wd:validation>
      </wd:datatype>

      <wd:split pattern="([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})">
        <wd:map group="1" field="day"/>
        <wd:map group="2" field="month"/>
        <wd:map group="3" field="year"/>
        <wd:failmessage>Not a valid date.</wd:failmessage>
      </wd:split>
      <wd:combine expression='Date(year, month, day)'/>

      <wd:widgets>
        <wd:field id="day" required="true">
          <wd:datatype base="integer"/>
          <wd:label>
            Enter Day
            <br/><small>(Day should be between 1 to 15)</small>
          </wd:label>
          <wd:validation>
            <wd:range min="1" max="15">
              <wd:failmessage>Enter date between 1st and 15th day of the month.</wd:failmessage>
            </wd:range>
          </wd:validation>
        </wd:field>
        <wd:field id="month" required="true">
          <wd:label>
            Enter Month
            <br/><small>(Month should be between 1 to 12)</small>
          </wd:label>
          <wd:datatype base="integer"/>
          <wd:selection-list>
            <wd:item value="">
              <wd:label>Select Month</wd:label>
            </wd:item>
            <wd:item value="1">
              <wd:label>January</wd:label>
            </wd:item>
            <wd:item value="2">
              <wd:label>February</wd:label>
            </wd:item>
            <wd:item value="3">
              <wd:label>March</wd:label>
            </wd:item>
            <wd:item value="4">
              <wd:label>April</wd:label>
            </wd:item>
            <wd:item value="5">
              <wd:label>May</wd:label>
            </wd:item>
            <wd:item value="6">
              <wd:label>June</wd:label>
            </wd:item>
            <wd:item value="7">
              <wd:label>July</wd:label>
            </wd:item>
            <wd:item value="8">
              <wd:label>August</wd:label>
            </wd:item>
            <wd:item value="9">
              <wd:label>September</wd:label>
            </wd:item>
            <wd:item value="10">
              <wd:label>October</wd:label>
            </wd:item>
            <wd:item value="11">
              <wd:label>November</wd:label>
            </wd:item>
            <wd:item value="12">
              <wd:label>December</wd:label>
            </wd:item>
          </wd:selection-list>
        </wd:field>
        <wd:field id="year" required="true">
          <wd:label>
            Enter Year
            <br/><small>(Year should be between 1990 to 2010)</small>
          </wd:label>
          <wd:datatype base="integer"/>
        </wd:field>
      </wd:widgets>
    </wd:aggregatefield>

    <wd:submit id="switch" action-command="switch" validate="false">
      <wd:label>Switch</wd:label>
    </wd:submit>
  </wd:widgets>
</wd:form>
