Sahana | Posts: 6

Code to make a textfield mandatory

0 votes
Hi Duo, As discussed, could you please provide the codeshare / snippet to mark a text field manadtory? Below is the client's requirement: if we add into the document a text field which the signer has to fill out, can we make that mandatory and can we request that this field is filled out only be specific signers? Let me know if you need any other information. Thanks!

Duo_Liang | Posts: 3776

Reply to: Code to make a textfield mandatory

0 votes
Hi Sahana, The feature your requirement mentioned was Field Validator, kindly check our Field Validators guide. And here's a working code snippet in Java SDK:
		
		EslClient client = new EslClient(API_KEY, API_URL);
		String signerEmail = "[email protected]";
		
		DocumentPackage pkg1 = PackageBuilder.newPackageNamed("Sample Contract")
				.withSigner(SignerBuilder.newSignerWithEmail(signerEmail)
						.withFirstName("John")
						.withLastName("Smith")
						)
				.withDocument(DocumentBuilder.newDocumentWithName("Contract")
						.fromFile(FILE_PATH)
						.withSignature(SignatureBuilder.signatureFor(signerEmail)
								.onPage(0)
								.atPosition(100, 100)
								.withField(FieldBuilder.textField()	
										.onPage(0)
										.atPosition(100, 200)
										.withValidation(FieldValidatorBuilder.basic()
												.required()
												.withErrorMessage("This field is mandatory!"))
										)
								)
						)
				.build();
		
		PackageId packageId = client.createAndSendPackage(pkg1);
		
		System.out.println(packageId);

With above code, you can assign a signature to a signer, and bind the text field to this signature, so that the text field is only visible to this specific signer during signing ceremony. Also, we used a field validator with required attribute to make the textfield mandatory. Hope this could help! 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