0

I'm using Orbeon 2019.2 CE on Tomcat 8, using plain XForms.

I have xml schema for xml docs that will completed by several people, so I need to be conscious of whether the document will be valid before it is complete. For date fields, I understand there are three main ways of creating a "date or blank" type:

  • using xsi:nil
  • making a union type of an xs:date and empty string
  • using a list type containing an xs:date that can have a length of 0 or 1.

I've tried the 2nd and third way, this works as expected for xml validation, but in XForms where I have specified the schema in the model, the datepicker control doesn't seem to work with the custom type. I would like to use schema validation and have an empty date field be valid. (I know about xf:date allowing no value vs. xs:date that doesn't). There is no problem when not using schema validation, but I really would like to be able to use it as it "externalizes" validation rules to some extent. I am also using the form runner error summary component. When using validation (<model schema='uri_to_schema'>), and a "date or nothing" type in the schema (as described above) I see this:

  • If date field binding does not specify xs:date or xf:date, no datepicker appears with the xf:input field. Typing a date with the format "2000-01-01" is valid, a blank field is valid, and anything else gets flagged as invalid (both by the error component and external validation). I also noticed that Orbeon is aware that is a custom type, as the class xforms-type-custom-date-or-nothing appears in the HTML ("date-or-nothing" is the name of the type).
  • If I put type='xs:date' in the binding for the date field, no datepicker appears, and the input is flagged as invalid (until you enter a date value)
  • If I put type='xf:date' in the binding, the field initially presents without the datepicker. If I put a valid date (format: yyyy-mm-dd), it's not flagged. If I put anything else (like 'abc'), it will be flagged by the error component, then the datepicker will appear, but it will be empty. However, in FormInspector, the field still has the invalid value, and the document (through external validation) is invalid. If I subsequently select a valid date from the datepicker, the flagged error goes away, but the field is blank again.
  • If I change the schema to use xs:date instead of the custom type ("date-or-nothing"), all is well using schema validation, except the document is invalid until it has a date value.
  • I have the schema instance referenced in the xform. I did try referencing the actual type from the schema by including the namespace of the schema in the xform, and then putting type='mydoc:date-or-nothing', but I have not been able to get this to work.
  • If I remove the schema from the model and use xf:date in the binding, all is well but now I don't have schema validation.

Does anyone have an option where I could use the custom type and have the datepicker appear? I don't see much documentation on using XML schema with xforms, so I'm guessing this might be an "edge case" that's not supported. Is there a way to "force" Orbeon to render a datepicker? (I looked to see if I could specify the "form-runner" component there, but the documentation only mentions other date control types). In searching, I thought I saw that the xforms specification allows an "appearance='date'" attribute on the "xf:input", but this is probably wrong as I could find no other mention of this.

It would be pretty disappointing if I had to ditch schema-based validation for any document that has a date field. In some cases, I could "get away" with making the date field mandatory for the first contributor of the document, but having the option would be much better. Thanks for any suggestions!

  • Hi Francis, I'd suggest we take the items you mentioned in your question one-by-one, starting with your second bullet point: "If I put `type='xs:date'` in the binding for the date field, no datepicker appears, and the input is flagged as invalid (until you enter a date value)". Could you create the simplest standalone example that reproduces this, put on on Pastebin or similar, and link to it in a comment? -Alex – avernet Feb 16 '22 at 19:03
  • Hi Francis, just checking: is this still an issue for you? If so, is there a chance you would be able to create an example we can use to reproduce the problem? -Alex – avernet Mar 01 '22 at 00:39
  • Hi! Thanks for the reply. I will try to prepare something minimal that reproduces the problem, it's just the matter of having the time. In the past I tried to get such things to "fit" in the application I'm working on, but maybe I should just try to run it from the Orbeon application. Any suggestions on the simplest way to create a test xform? – Francis Parsons Mar 02 '22 at 13:55
  • Hi Francis, I know the feeling ;), no rush on my side. About the date validation, in most cases, schemas are not used for this; in Form Builder you just add a date field, and Orbeon Forms validates the value as a date, without the need for a schema. Would this be good enough in your case? Or you maybe had some other reason for wanting to use a schema? -Alex – avernet Mar 03 '22 at 22:25
  • We are doing xforms "by hand", and we keep a schema "library" that includes some schema common to all documents. Using schema reduces the amount of "manual" validation needed in the xforms. Orbeon is getting the schema from a jar file in it's lib folder. The "date or nothing" type validates correctly, but the date picker can't be invoked. Is there a way to"force" Orbeon to use it? – Francis Parsons Mar 05 '22 at 00:44
  • Hi Francis, go it about the XForms being written "by hand"; how is your XForms using it though? Would you be able to share with me a minimal example that I can run to reproduce the problem? -Alex – avernet Mar 07 '22 at 21:43

0 Answers0