W3C home > Mailing lists > Public > www-forms@w3.org > January 2006

XForms: how to disable the use of the XML Schema?

From: <Olivier.Gaillard@bit.admin.ch>
Date: Tue, 10 Jan 2006 09:24:27 +0100
Message-ID: <F9017844DF95F047B04B382336E68BEB030753F6@ad04mexefd4.ad.admin.ch>
To: www-forms@w3.org
Hello,
 

I use an XForms whose validation is driven by an XML Schema.
I'd like to disable the validation on-demand for some elements, because
we need to save the data even with empty or not valid values 
(reason is that we have mostly no rights to edit the data of 
a client).
 
I followed the solution explained by Micah Dubinko in "XForms
Essentials" pp. 171--172: the controls "Allow Empty PLZ" and "Empty
PLZ not allow" switch the value of the attribute "required" of element
"plz" (ZIP) to "true" or "false".
 
All works fine for *empty* values if the XML Schema definition is a
string and if empty strings are allowed:
 
<xs:restriction base="xs:string">
   <xs:pattern value="([0-9]{4})?"/>
</xs:restriction>
 

But if the pattern of the XML Schema does not contain the optional
sign `?' an empty string is not allowed.
 

If the definition is changed to integer:
 
<xs:element name="codePostal" type="xs:integer" nillable="true"
minOccurs="0"/>
 
and if the ZIP value is empty, there is no validation error (the
control does not become red), but I get an error message when I submit
the form, complaining that the value of ZIP is not an integer.
 
 
 
As non valid data must be saved the solution cannot come from the XML
Schema but from XForms.
 
--------
Question: Is it possible to disable the use of the XML Schema?
--------
 

<?xml version="1.0" encoding="ISO-8859-1"?>
<html xmlns:xf=" <http://www.w3.org/2002/xforms>
http://www.w3.org/2002/xforms" 
      xmlns:xsd=" <http://www.w3.org/2001/XMLSchema>
http://www.w3.org/2001/XMLSchema" 
      xmlns:ev=" <http://www.w3.org/2001/xml-events>
http://www.w3.org/2001/xml-events" 
      xmlns=" <http://www.w3.org/1999/xhtml> http://www.w3.org/1999/xhtml">
      <object classid="CLSID:4D0ABA11-C5F0-4478-991A-375C4B648F58"
id="formsPlayer"></object>
      <?import namespace="xf" implementation="#formsPlayer"?>
 <head>
 <style type="text/css">
    .invalid 
    {
       background-color: red;
    }
    body {background: floralwhite}
 </style>
  <xf:model id="m1" schema="./app4b.xsd"> 
   <xf:instance src="./app4b.xml" />
   <xf:bind id="villeNom" nodeset="/form/data/adresse/ville/villeNom" />
   <xf:bind id="plz" nodeset="/form/data/adresse/ville/codePostal" 
    required="instance('strict_flag')" />
   <xf:submission action="xformsHandler.html" enctype="application/xml" 
                                encoding="ISO-8859-1" id="submit"
method="post" /> 
          
      <xf:submission id="fsubmit" replace="instance" 
                                action="result.xml"
enctype="application/xml" 
                                encoding="ISO-8859-1"  method="put" />
   <xf:instance id="strict_flag">
    <flag>true</flag>
             </xf:instance>
  </xf:model>
      </head>
      <!-- Formular -->
  <body>
 <xf:input bind="villeNom">
   <xf:label>Ville</xf:label>
 </xf:input>
 <br/>
 
      
      <xf:input bind="plz">
       <xf:label>NPA</xf:label>    
      </xf:input>
      
    <br/>
  
     <xf:trigger>
       <xf:label>Allow empty ZIP</xf:label>
       <xf:action ev:event="DOMActivate">
  <xf:setvalue ref="instance('strict_flag')">false</xf:setvalue>
       </xf:action>
     </xf:trigger>
 
     <br/>
 
     <xf:trigger>
       <xf:label>Empty ZIP not allow</xf:label>
       <xf:action ev:event="DOMActivate">
  <xf:setvalue ref="instance('strict_flag')">true</xf:setvalue>
       </xf:action>
     </xf:trigger>
 
     <br/>
     <xf:label>Must ZIP be filled?
       <b><xf:output ref="instance('strict_flag')"></xf:output></b>
     </xf:label>
 
      <br/>
      <xf:submit submission="fsubmit">
 <xf:label>Write to disk</xf:label>
      </xf:submit>
 
 </body>
</html>
 
 
 
 
 
Here's the XML instance:
<?xml version="1.0" encoding="iso-8859-1"?>
<form>
 <data>
  <adresse>
   <ville>
    <villeNom>Be</villeNom>
    <codePostal>0000</codePostal>
   </ville>
  </adresse>
 </data>
</form>
 
 
 
Thanks in advance for your help,
 
Olivier
 
 
Received on Tuesday, 10 January 2006 09:47:13 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:02 GMT