Empty field pattern validation failure when required=false()

  • Mike

    Mike - 2014-03-28

    Hi again Alain,

    I am just trying to understand the expected validation logic for strongly typed binds. For simple strings it would seem that the logic works as expected - i.e. where required=true() and the value is blank it fails validation, however if required=false() then the field does not need to be populated.

    When it comes to other strongly typed fields the picture is not the same. For instance with dates, even when required=false() and the field is blank it fails validation as the pattern does not match the expected date pattern. See below for an example.

    Any thoughts?



    <html xmlns="http://www.w3.org/1999/xhtml"
        <title>XSLTForms testing</title>
          <xf:instance id="test-instance">
            <data xmlns="">
          <xf:bind id="String1" nodeset="instance('test-instance')/string1" required="true()" type="xs:string"/>
          <xf:bind id="String2" nodeset="instance('test-instance')/string2" required="false()" type="xs:string"/>
          <xf:bind id="Date1" nodeset="instance('test-instance')/date1" required="true()" type="xs:date"/>
          <xf:bind id="Date2" nodeset="instance('test-instance')/date2" required="false()" type="xs:date"/>
          <xf:bind id="Boolean1" nodeset="instance('test-instance')/boolean1" required="true()" type="xs:boolean"/>
          <xf:bind id="Boolean2" nodeset="instance('test-instance')/boolean2" required="false()" type="xs:boolean"/>
          <xf:bind id="Decimal1" nodeset="instance('test-instance')/decimal1" required="true()" type="xs:decimal"/>
          <xf:bind id="Decimal2" nodeset="instance('test-instance')/decimal2" required="false()" type="xs:decimal"/>
        <xf:input bind="String1">
          <xf:label>String 1</xf:label>
          <xf:alert>This is required</xf:alert>
        <xf:input bind="String2">
          <xf:label>String 2</xf:label>
          <xf:alert>This is not required</xf:alert>
          <xf:input bind="Date1">
            <xf:label>Date 1</xf:label>
            <xf:alert>This is required</xf:alert>
        <xf:input bind="Date2">
          <xf:label>Date 2</xf:label>
          <xf:alert>This is not required</xf:alert>
        <xf:input bind="Boolean1">
          <xf:label>Boolean 1</xf:label>
          <xf:alert>This is required</xf:alert>
        <xf:input bind="Boolean2">
          <xf:label>Boolean 2</xf:label>
          <xf:alert>This is not required</xf:alert>
        <xf:input bind="Decimal1">
          <xf:label>Decimal 1</xf:label>
          <xf:alert>This is required</xf:alert>
        <xf:input bind="Decimal2">
          <xf:label>Decimal 2</xf:label>
          <xf:alert>This is not required</xf:alert>
  • Jarosław Kowalewski


    The solution is to use xforms:date type insted xs:date. xs:date cannot be empty but xforms type permits it.

    If you want use xs: type you have to define union type.

    Let me know if it is a solution.


    Last edit: Jarosław Kowalewski 2014-09-12
  • Mike

    Mike - 2014-10-02

    Hi Jarek,

    For some reason sourceforge did not mail me updates so only just spotted your response.

    Yes I independently come to the realisation that I needed to use xf:date instead and this now works fine.

    It seems to me that use of xs data types and the overlap with the @required attribute is a little awkward - but I am happy as I have a workaround for now.



    Last edit: Mike 2014-10-02
    • Jarosław Kowalewski

      Hi Mike,

      To do the same in xsd you should use union element. And that works on xsd level. The problem is that parser must analize xsd and then decide if it's a date or unionType date, discover it's requiered or not. It's much easier to use xf:date and @required attribute.

      Further on xforms level you can control if field is required or not, according to another fields state. What you are using xsd type it's not possible.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks