Page 1 of 1

Required fields based on multiple conditions

Posted: 22 Feb 2017
by VGrutle
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!

Re: Required fields based on multiple conditions

Posted: 27 Feb 2017
by Dmitry Kozlov
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;
});

Re: Required fields based on multiple conditions

Posted: 27 Feb 2017
by VGrutle
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; });

Re: Required fields based on multiple conditions

Posted: 28 Feb 2017
by Dmitry Kozlov
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.

Re: Required fields based on multiple conditions

Posted: 28 Mar 2017
by vegard.grutle
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

Re: Required fields based on multiple conditions

Posted: 28 Mar 2017
by MFatima
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;
});

Re: Required fields based on multiple conditions

Posted: 29 Mar 2017
by Dmitry Kozlov
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>')

Re: Required fields based on multiple conditions

Posted: 29 Mar 2017
by Dmitry Kozlov
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.

Re: Required fields based on multiple conditions

Posted: 29 Mar 2017
by vegard.grutle
Thanks, Dmitry! I will try that!

Re: Required fields based on multiple conditions

Posted: 29 Mar 2017
by MFatima
Thanks Dmitry