michailtouloupis | Posts: 40

Date field validation

0 votes

Hello,

In Java, I would like to add a new field where the signer should fill in a date (in a date format DD/MM/YYYY).

  • What type of field should it be?
  • The signer should be allowed to add either the current date or one from the past. Not a future date. Is there any way to validate it and show an error message in case the validation is not passed?

Thanks,

Michail


Duo_Liang | Posts: 3776

Reply to: Date field validation

1 votes

Hi Michail,

 

You can use either text field or date picker field. But with both types, there's temporary no way to limit the input value to be a past or current date. We can definitely raise it as an Enhancement Request but it's not available yet.

 

If you choose to use date picker field, use below SDK code or API JSON:

 

Java SDK:

        Field datepickerField = FieldBuilder.datepicker()
         .onPage(0)
         .atPosition(100, 100)
         .withSize(150, 50)
         .withValidation(FieldValidatorBuilder.datepickerFormat("dd-MM-YYYY").withErrorMessage("Please select a current or past date!"))
         .build();

 

REST API:

{
  "validation": {
    "required": true,
    "errorMessage": "Please select a current or past date!",
    "pattern": "dd-MM-YYYY"
  },
  "id": "gjmeqWErMVoG",
  "page": 0,
  "subtype": "DATEPICKER",
  "left": 125,
  "top": 83,
  "width": 150,
  "height": 50,
  "type": "INPUT"
}

 

Duo


michailtouloupis | Posts: 40

Reply to: Date field validation

0 votes

Hello Duo,

Thanks for your answer and your code examples.

  1. From what I understand, the validation error of the date picker will be shown only in case the signer types a wrong format date? Or in case he left the field empty?
  2. Apart from that, would it be possible to have the following approach? The signer selects a date from the date picker. By the selection, a pop up is displayed with the message: "Please confirm that the selected date is not a future date" and two buttons Yes and No. By clicking on Yes, the process contines. By clicking on No, the signer has to select a date again.

 

Best Regards,

Michail

 


Duo_Liang | Posts: 3776

Reply to: Date field validation

1 votes

Hi Michail,

 

The field validator in both classic and new signer experience could only tell if the format is wrong (if the value is passed in through API), or if the field is empty. Field validator also supports regular expression, but since the current date is dynamic, it's not very likely to match the current date by a RegExr. And it's not possible to hijack the validation process and provide a confirmation popup. 

I would suggest we fill in an Enhancement Request asking for a native validator type for future/past date.

 

Duo 


michailtouloupis | Posts: 40

Reply to: Date field validation

0 votes

Hello Duo,

If we fill in an Enhancement Request, when do you think it will be available in Sandbox (US1) and Production (US1) environments?

Thanks and Regards,

Michail


Duo_Liang | Posts: 3776

Reply to: Date field validation

1 votes

Hi Michail,

 

In order to fill in an Enhancement Request, please supply a brief description and your business motivation behind this suggestion. After we added your submission to our database of enhancement requests, product team would review and evaluate the suggestion based on a number of factors, including:

  • Market need and competitive advantage
  • Technical feasibility
  • How it impacts the overall UX
  • Number of customers & prospects requesting it

We will be in touch in 5-7 business days to let you know if your enhancement request is accepted or declined for roadmap consideration. However, we cannot guarantee that your request will be added to our roadmap and it's hard to tell the ETA until the feature has already been on the roadmap plan.

 

Duo


michailtouloupis | Posts: 40

Reply to: Date field validation

0 votes

Hello Duo,

 

From which release is the datepicker available in the FieldBuilder?

I use the 10.9.1 sdk of OneSpan and when I try to use the FieldBuilder.datepicker() in Java, I get the following error:

The method datepicker() is undefined for the type FieldBuilder

 

Best Regards,

Michail


Duo_Liang | Posts: 3776

Reply to:

1 votes

Hi Michail,

 

I believe this field type is supported in SDK since version 11.0.1, see below Git history:

https://github.com/OneSpan/esl.sdk.java/commit/06ca7a86392469d4486df1db8e57aeb4595c617f#diff-0148ed8ca253049290a76a05d9f07ade0c23ab6c6e20aabc094b74ef599c7a78

 

Duo


michailtouloupis | Posts: 40

Reply to: Date field validation

0 votes

Hello Duo,

 

Thanks for your answer. Unfortunately, we cannot simply use the new version of sdk, as it has to be checked and approved by our security team first. And it might take time.

Is it possible to build the datepicker locally somehow? By executing the code of sdk locally?

 

Thanks and Regards,

Michail


Duo_Liang | Posts: 3776

Reply to:

1 votes

Hi Michail,

 

There's no need to modify the SDK source code and you can create a date picker field use below code instead:
        FieldBuilder datepicker = FieldBuilder.newField()
                .withStyle(FieldStyle.UNRECOGNIZED("DATEPICKER"))
                .withValidation(FieldValidatorBuilder.regex("YYYY-MM-dd").withErrorMessage("Please select a current or past date!"))

                .onPage(0)
                .atPosition(200, 100)
                .withSize(200, 55);

However, because date picker field is not part of the SDK 10.9.1 modelling, the field won't be returned in .getPackage() function.

 

Duo


michailtouloupis | Posts: 40

Reply to: Date field validation

0 votes

Hello Duo,

 

Many thanks for the helpful answer.

Two clarifications please:

  1. .withValidation(FieldValidatorBuilder.regex("YYYY-MM-dd") --> This will force the format "YYYY-MM-dd"? I need the format "DD/MM/YYYY"
  2. the field won't be returned in .getPackage() function --> What does it mean?

 

Best Regards,
Michail


Duo_Liang | Posts: 3776

Reply to:

1 votes

1. then use "dd-MM-YYYY" instead (I changed it for testing purpose)

2. if you loop through all fields, this date picker field won't be printed out:

        DocumentPackage package1 = eslClient.getPackage(packageId);
        for (Document document : package1.getDocuments()) {
            for (Signature signature : document.getSignatures()) {
                for (Field field : signature.getFields()) {
                    System.out.println(field.getId() + " " + field.getStyle().name());
                }
            }
        }

At the lower level, this is caused because the SDK indicates its version in the request and therefore the API response didn't return the unsupported field types. 

 

Duo


michailtouloupis | Posts: 40

Reply to: Date field validation

0 votes

Hello Duo,

 

How can I set it to mandatory, at the same time?

 

Regards,
Michail


Duo_Liang | Posts: 3776

Reply to:

1 votes

Add the .required() to the chain of functions:

        FieldBuilder datepicker = FieldBuilder.newField()
                .withStyle(FieldStyle.UNRECOGNIZED("DATEPICKER"))
                .withValidation(FieldValidatorBuilder.regex("dd-MM-YYYY").required().withErrorMessage("Please select a current or past date!"))
                .onPage(0)
                .atPosition(200, 100)
                .withSize(200, 55);

 

Duo


michailtouloupis | Posts: 40

Reply to: Date field validation

0 votes

Many thanks Duo! It works!

As default message in the date picker box, is written (in French): Cliquer pour etablir

Is it possible to change this message to a different one, which I can define?

Best Regards,
Michail


michailtouloupis | Posts: 40

Reply to:

0 votes

Hello Duo,

 

Yes, I am aware of this change. Is there a different behavior of the date picker in the New Signer Experience?

Is it possible to change the "Cliquer pour etablir" in the Classic Signer Experience, via Java?

 

Regards,
Michail


michailtouloupis | Posts: 40

Reply to: Date field validation

0 votes

One more question Duo:

I tried with the date format "dd/MM/YYYY" and I got the error 

Optional details: {"messageKey":"error.validation.field.badDateFormat","message":"The field's value does not conform to the required date format.","code":400,"name":"Validation Error"}

Does it mean that the format "dd/MM/YYYY" is not supported and I have to use the format "dd-MM-YYYY" ?

Best Regards,
Michail


Duo_Liang | Posts: 3776

Reply to:

1 votes

Yes, it's possible to customize this UI label, but it can only be set up by support team([email protected]), with below resource name:
"esl.templates.package_form.click_to_set":"placeholder text"
 

Essentially there shouldn't have functional differences in new and classic signer experiences, it just provides a different look and feel. And for the UI label, new signer experience displays the format e.g. "YYYY-MM-DD" instead of different translations of "click to set".

 

Duo


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off