Make fields mandatory using a radio button

rss

Posted by Hir - Jul 6 ’16 at 11:14

Hello,

I have a radio button with choices yes and no, i would like to make field A,B and C ( these are all single line fields) mandatory if radio button choice is selected as 'Yes'. I have tried to use couple of different validations but it always checks to be true even when radio button is selected as 'No'. Can you please help with this? Thanks in advance!

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 18 days
    #1 by Dmitry Kozlov Jul 7 ’16 at 09:27

    Hi,

    If you use the Choice field, fd.field().value() will return 0-based index of the selected option:

     
    fd.onsubmit(function() {
        if (fd.field('FieldName').value() == 0) {
            //check mandatory fields here
            //return false;
        }
        
        return true;
    });
    

    Please, read the post:

    http://formsdesigner.blogspot.com/2013/04/getting-and-setting-sharepoint-form.html

  • Hir
    Member
    Member for: 3 years 5 months 1 day
    #2 by Hir Jul 7 ’16 at 04:55

    Thanks for your replay. I got it working with following.

    fd.onsubmit(function(){

    if ((fd.field('Choice Field').value() == 1) && (fd.field('A').value()=="")|| (fd.field('B').value=="")||(fd.field('C').value=="")){

    alert('Fields A, B and C cannot be left blank if choice is No.');

    return false;

    }

    return true;

    })

     

  • lijupnandanan
    Member
    Member for: 3 years 7 months 26 days
    #3 by lijupnandanan Sep 21 ’16 at 11:16

    Hi

    I get radiobutton value from this

    fd.field('FieldName').value()

     

    but how can I get radio button text?

  • Yuriy Medvedev
    Yuriy Medvedev
    Moderator
    Member for: 3 years 3 months 8 days
    #4 by Yuriy Medvedev Sep 22 ’16 at 06:04

    [#3]:

    Hello!

    Label of choosen radio you can get by this script:

     

    fd.field('Choice').control()._el().find( "input:checked" ).next().text()

     

    where Choice is the internal name of column with radio-buttons.

Displaying 1 to 4 of 4 messages