The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Widget

abjaffrey
Giga Guru

Hi,

 

i have a requirement to poplate a table of data of assets assigned with yes/no box.

i have written a widget script to populate, however the both the yes and no are getting clicked simultaneously, i only want either yes or no to be selected,

 

HTML:

<input type="checkbox" name="yes" id="yes" value="Ja" ng-click="c.setAction(item)">

<input type="checkbox" name="no" id="no" value="Nej" ng-click="c.setnoAction(item)">

 

client:

c.setAction = function(item) {
        item.yes_no = 'Yes';
        document.getElementById("no").checked = false;
        $('#' + item.asset).slideUp(400);
        g_form.setValue('personlige_assets', JSON.stringify(c.data.assets));
    };
 
c.setnoAction = function(item) {
        item.yes_no = 'No';
        item.notes = '';
        document.getElementById("yes").checked = false;
        $('#' + item.asset).slideDown(400);
        g_form.setValue('personlige_assets', JSON.stringify(c.data.assets));

    };
9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

 

@abjaffrey 

you should use radio buttons instead of checkboxes

HTML:

<input type="radio" name="yes_no" id="yes" value="Ja" ng-click="c.setAction(item)">
<label for="yes">Yes</label>

<input type="radio" name="yes_no" id="no" value="Nej" ng-click="c.setnoAction(item)">
<label for="no">No</label>

Client Script:

c.setAction = function(item) {
    item.yes_no = 'Yes';
    $('#' + item.asset).slideUp(400);
    g_form.setValue('personlige_assets', JSON.stringify(c.data.assets));
};

c.setnoAction = function(item) {
    item.yes_no = 'No';
    item.notes = '';
    $('#' + item.asset).slideDown(400);
    g_form.setValue('personlige_assets', JSON.stringify(c.data.assets));
};

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

hi Ankur

 

It didnt work

abjaffrey_0-1736764439825.png

 

have already tried radio, however only one yes and no im able to select in total

 

Thing is the code is only working on first row rest all its not working