Required fields based on multiple conditions

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
VGrutle
Posts: 3
Joined: Fri Mar 03, 2017

22 Feb 2017

Hi,

I have reviewed the blogpost (http://formsdesigner.blogspot.no/2014/0 ... -make.html) about conditionally setting mandatory fields. As i understand this code only accommodate for one condition.

In my case i have one lookup field (Case type) and one Choise field (status - radio button) that shall define which fields needs to be mandatory.

Any help is appriciated!

Thanks!

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

27 Feb 2017

Hi,

Then you just need to use a complex condition like that:

Code: Select all

fd.onsubmit(function () {
    if (fd.field('Field1').value() == 'X' && 
        fd.field('Field12).value() == 'Y') {
        if (!fd.field('DueDate').value()) {
            alert('Please, fill in the Due Date field.');
            return false;
        }
    }

    return true;
});

VGrutle
Posts: 3
Joined: Fri Mar 03, 2017

27 Feb 2017

Thanks! But unfortenately this did not work out for me.

How do I embed this into the code given in the example?

function setRequiredFields() { if (fd.field('AssignedTo').value().dictionaryEntries.length != 0) { // Add asterisks fd.field('DueDate').titleRequired(true); } else { // Remove asterisks fd.field('DueDate').titleRequired(false); } } // Calling setRequiredFields when the user changes the assignment fd.field('AssignedTo').change(setRequiredFields); // Calling setRequiredFields on form loading setRequiredFields(); // Custom validation fd.onsubmit(function () { if (fd.field('AssignedTo').value().dictionaryEntries.length != 0) { if (!fd.field('DueDate').value()) { alert('Please, fill in the Due Date field.'); return false; } } return true; });

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

28 Feb 2017

Could you send the detailed description of your case (which fields become mandatory based on what choice) and a screenshot of your form to support@spform.com? Our support team will estimate the task.

User avatar
vegard.grutle
Posts: 59
Joined: Fri Mar 17, 2017

28 Mar 2017

Hi, again Dmitry!

Is there a way I can capture the error message from setting the asterisks on the fields.

Example: A field is set to mandatory (*) by the code given in the blog referenced above. How could I display the message e.g. "You cant leave this field blank" below the field?

Thanks in anticipation!

V

MFatima
Posts: 13
Joined: Wed Feb 24, 2016

28 Mar 2017

Hi Dmitry,

I have used the code below but it is not working on the mobile side. It prompts once on save but when closing the prompt message it also cancel the form.


// Custom Validation
fd.onsubmit(function () {
if (fd.field('Engine_x0020_Oil_x0020__x002d__x').value() === "" && fd.field('Engine_x0020_Oil_x0020_Level').control().value() != '1' ) {
alert('Please, fill in the comment for Engine Oil Level!');
return false ;
}


if (fd.field('Fluid_x0020_Leaks_x0020__x002d__').value() === "" && fd.field('Fluid_x0020_Leaks').control().value() != '1' ) {
alert('Please, fill in the comment for Fluid Leaks!');
return false ;
}

return true;

});


Can you please help... it works fine on the browser side.

Thanks,

Mariam



Dmitry Kozlov wrote:
27 Feb 2017
Hi,

Then you just need to use a complex condition like that:

Code: Select all

fd.onsubmit(function () {
    if (fd.field('Field1').value() == 'X' && 
        fd.field('Field12).value() == 'Y') {
        if (!fd.field('DueDate').value()) {
            alert('Please, fill in the Due Date field.');
            return false;
        }
    }

    return true;
});

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

29 Mar 2017

Hi!
vegard.grutle wrote:
28 Mar 2017
Example: A field is set to mandatory (*) by the code given in the blog referenced above. How could I display the message e.g. "You cant leave this field blank" below the field?
You should validate the field in the onsubmit handler and display a message, say, in the alert box:

Code: Select all

fd.onsubmit(function () {
  if (!fd.field('DueDate').value()) {
    alert('Please, fill in the Due Date field.');
	return false;
  }
 
  return true;
});
Or right under the field:

Code: Select all

fd.field('Title').control()._el().append('<span class="ms-formvalidation">Please, fill in the Due Date field.</span>')

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

29 Mar 2017

Hi!
MFatima wrote:
28 Mar 2017
I have used the code below but it is not working on the mobile side. It prompts once on save but when closing the prompt message it also cancel the form.
I have just created a simple form with only Title field and inserted the following validation:

Code: Select all

fd.onsubmit(function() {
	if (!fd.field('Title').value()) {
		alert('Please, fill-in the Title field');
		return false;
	}
	
	return true;
});
It worked fine on iphone (safari browser). No redirection until the Title field is populated. So, most likely something wrong with your code, try to debug it.

User avatar
vegard.grutle
Posts: 59
Joined: Fri Mar 17, 2017

29 Mar 2017

Thanks, Dmitry! I will try that!

MFatima
Posts: 13
Joined: Wed Feb 24, 2016

29 Mar 2017

Thanks Dmitry

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests