Required fields based on multiple conditions
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!
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!
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
Then you just need to use a complex condition like that:
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;
});
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; });
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; });
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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.
- vegard.grutle
- Posts: 59
- Joined: Fri Mar 17, 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
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
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
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 2017Hi,
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; });
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi!
Or right under the field:
You should validate the field in the onsubmit handler and display a message, say, in the alert box:vegard.grutle wrote: ↑28 Mar 2017Example: 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?
Code: Select all
fd.onsubmit(function () {
if (!fd.field('DueDate').value()) {
alert('Please, fill in the Due Date field.');
return false;
}
return true;
});
Code: Select all
fd.field('Title').control()._el().append('<span class="ms-formvalidation">Please, fill in the Due Date field.</span>')
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi!
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.
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;
});
-
- Information
-
Who is online
Users browsing this forum: No registered users and 22 guests