loop all fields in fd

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
Jens.Hetze
Posts: 22
Joined: Sat May 20, 2017

09 Oct 2019

Hi SP Forms Designer team,

is there a possibility to loop all fields in fd object? I want to check all asterisks to implement a simple required validation.
Or is there a better possibility to do this?

Thanks in advance.
Jens

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

10 Oct 2019

Hello Jens.Hetze,

If the filed is required it will be validated by default.

If you need custom validation you can add it to your form with the help of Forms Designer's JS-framework and check whether all the required fields are filled in. Here is a sample:

Code: Select all

fd.onsubmit(function() {
	if (!fd.field('Field1').value()) {
	
		alert('Please, fill-in the Field 1');
		return false;
	}

	return true;
});
Please also have a look at the 'How to conditionally hide, disable, and make mandatory fields on SharePoint forms dynamically' article, 'Require field based on condition' part for more information.

User avatar
Jens.Hetze
Posts: 22
Joined: Sat May 20, 2017

10 Oct 2019

Hi mnikitina.

Thank you for your answer. Maybe it was too little information. I know that if the fields in SharePoint are marked as required, validation will be performed by default. In my case, however, all SharePoint columns are optional because they should be filled out in several workflow steps. For this reason, I would like to retrieve all fields marked with an asterisk in SP Forms Designer and implement my own validation.
I hope that helps to understand my case.

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

11 Oct 2019

Jens.Hetze,

You can add the Asterisk to the Field Name in the field settings.
Capture.PNG
Capture.PNG (4.17 KiB) Viewed 2913 times
And you can add custom validation using the script. This should be done for each field separately

Code: Select all

fd.onsubmit(function() {
	if (!fd.field('Field2').value()) {
	
		alert('Please, fill-in the Field 2');
		return false;
	}

	return true;
});

fd.onsubmit(function() {
	if (!fd.field('Field2').value()) {
	
		alert('Please, fill-in the Field 2');
		return false;
	}

	return true;
});
or you can use one validator for all fields.

Code: Select all

fd.onsubmit(function() {
	if (!fd.field('Field1').value() || !fd.field('Field2').value() || !fd.field('Field3').value()) {
	
		alert('Please, fill-in required fields');
		return false;
	}

	return true;
	});

Anyway you need to specify each field that you want to validate.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests