Radio button validation on group instead of individual radio buttons
Monday, December 28, 2020 at 10:34amI'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
Monday, December 28, 2020 at 11:21amHi 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
Reply to: Radio button validation on group instead of individual radio buttons
Monday, December 28, 2020 at 11:35amIt 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: Hi praxedis, Radio…
Monday, December 28, 2020 at 11:37amHi Duo. 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.
Reply to: Radio button validation on group instead of individual radio buttons
Monday, December 28, 2020 at 12:20pmHi 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
Reply to: Hi praxedis, Radio…
Monday, December 28, 2020 at 12:22pmThank you! I thought so but I wanted to confirm.
Reply to: Hi praxedis, Radio…
Monday, January 4, 2021 at 11:52amHi @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
Tuesday, January 5, 2021 at 10:03amHi 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