Make a text field mandatory based on a condition
Posted: 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.
// 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.