Make a text field mandatory based on a condition

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
JacobHolmLaursen
Posts: 6
Joined: Wed Jun 29, 2016

15 Feb 2017

I have managed to show an alert if a user submits a form and has selected a certain value in one choice field and another value in another field. It looks like this:

// Alert about validation
fd.onsubmit(function() {
if ((fd.field('Angiv_x0020_din_x0020_beslutning').value() == 'Approve') && (fd.field('Registrering_x0020_i_x0020_MUS_x').value() == '--- Please select a value---')) {
alert('Please remember to select a value.');
return false;
}
return true;
});


But I have not managed to do the same with a field of the type “Single line of text” og “Multiple line of text”. I want to do something like this:

// Alert if a value is selected and a text field is empty
fd.onsubmit(function() {
if ((fd.field('Angiv_x0020_din_x0020_beslutning').value() == 'Approve') && (fd.field('Depot').value() == "")) {
alert('Please write some text in the field Depot');
return false;
}
return true;
});

I haven’t manage to find an answer in the other forum topics.

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

16 Feb 2017

Hi,

If you use Enhanced RTE field, try this:

Code: Select all

if ((fd.field('Angiv_x0020_din_x0020_beslutning').value() == 'Approve') &&
   ($(fd.field('FieldName').value()).text() == "")) {
...

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests