praxedis

Radio button validation on group instead of individual radio buttons

0 votes

I'd like to do validation on a group of radio buttons to just check to see if one has been chosen. If none are chosen then validation kicks in. Is there sample code for this?


Reply to: Radio button validation on group instead of individual radio buttons

0 votes

Hi praxedis,

 

Radio button fields with "Required" validator ensures at least and only one of the predefined options will be chosen during the signing, check below sample code:

 

        DocumentPackage pkg = PackageBuilder.newPackageNamed("Example Package")
                .withSigner(SignerBuilder.newSignerWithEmail("[email protected]")
                        .withFirstName("John")
                        .withLastName("Smith")
                        )
                .withDocument(DocumentBuilder.newDocumentWithName("Document1")
                        .fromFile(FILE_PATH)
                        .withSignature(SignatureBuilder.signatureFor("[email protected]")
                                .onPage(0)
                                .atPosition(100, 100)
                                .withField(FieldBuilder.radioButton("group1")    
                                        .withId(new FieldId("option1"))
                                        .withName("option1")
                                        .onPage(0)
                                        .atPosition(100, 200)
                                        .withSize(10, 10)
                                        .withValidation(FieldValidatorBuilder.basic()
                                                .required()
                                                .withErrorMessage("This field is mandatory!"))
                                        )

                                .withField(FieldBuilder.radioButton("group1")    
                                        .withId(new FieldId("option2"))
                                        .withName("option2")
                                        .onPage(0)
                                        .atPosition(200, 200)
                                        .withSize(10, 10)
                                        .withValidation(FieldValidatorBuilder.basic()
                                                .required()
                                                .withErrorMessage("This field is mandatory!"))
                                        )
                                .withField(FieldBuilder.radioButton("group1")    
                                        .withId(new FieldId("option3"))
                                        .withName("option3")
                                        .onPage(0)
                                        .atPosition(300, 200)
                                        .withSize(10, 10)
                                        .withValidation(FieldValidatorBuilder.basic()
                                                .required()
                                                .withErrorMessage("This field is mandatory!"))
                                        )
                                )
                        )
                .withStatus(PackageStatus.SENT)
                .build();
        
        PackageId createPackage = eslClient.createPackageOneStep(pkg);

 

I hardcoded the x/y coordinates in above example. On top of that, radio button field is also supported by Text Tags syntax, please refer to the guide here.

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Radio button validation on group instead of individual radio buttons

0 votes

It looks like you have "withValidation" set on each one of the group options. Wouldn't that mean that every option is required? I only want the code to check to see if one of the options has been chosen. Not all of them.


Reply to: Radio button validation on group instead of individual radio buttons

0 votes

Hi praxedis,

 

Radio button group, by its nature, allows signer to choose at most one option in the same group ("group1" in above example). Therefore, both should work if you set "withValidation" for any one or for all radio button fields.

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to:

0 votes

Hi @Duo_Liang

I have six different options in my radio button group and when I try and sign without choosing one, I am seeing six validation error messages - one message for each option - even though I have "withValidation" set to just one field. I only want one validation error to appear. Is there a way to do this?

Thanks.


Reply to: Radio button validation on group instead of individual radio buttons

0 votes

Hi praxedis,

 

Sorry for the late reply as I was off yesterday. It should be expected that "there's only one error message per radio group when the group is required." However, it's a known defect in classic Signing Ceremony as you may have experienced. So before it's fixed, you have following workarounds:

(1)give one of the options a default value "X"

                                .withField(FieldBuilder.radioButton("group1")    
                                        .withId(new FieldId("option1"))
                                        .withName("option1")
                                        .onPage(0)
                                        .atPosition(100, 200)
                                        .withSize(10, 10)
                                        .withValidation(FieldValidatorBuilder.basic()
                                                .required()
                                                .withErrorMessage("This field is mandatory!"))

                                       .withValue("X")
                                        )

(2)or move to New Signer Experience

Back to the issue itself, for the time being we do not have a timeline for the fix but I can help you fill in a support ticket and ask for it if you preferred.

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


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