Make a text field mandatory based on a condition

rss

Posted by JacobHolmLaursen - Feb 15 ’17 at 04:56

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.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 5 years 10 months 28 days
    #1 by Dmitry Kozlov Feb 16 ’17 at 03:27

    Hi,

    If you use Enhanced RTE field, try this:

    if ((fd.field('Angiv_x0020_din_x0020_beslutning').value() == 'Approve') &&
        ($(fd.field('FieldName').value()).text() == "")) {
    ...
    
Displaying 1 to 1 of 1 messages