Use radio buttons to restrict field edits

This sample code restricts certain fields from being edited, depending on the choice chosen in the radio button field.

Sample Image

restrictonchoice.gif

Sample Code

// Use the Radio button to restrict field edits

(function() {
    "use strict";

    var CHOICE = 'radio_button_field'; //field code of radio button
    var FIELD_A = 'FieldA'; //field code of the field to be restricted
    var FIELD_B = 'FieldB'; //field code of another field to be restricted
    var FIELD_C = 'FieldC'; //field code of one more field to be restricted
    
    var events = ["app.record.create.show", "app.record.edit.show",
                  "app.record.create.change." + CHOICE, "app.record.edit.change." + CHOICE];

    kintone.events.on(events, function(event) {
        var record = event.record;
        var toggleVal = record[CHOICE].value;

        if (toggleVal === "A") {
            record[FIELD_A].disabled = false;
            record[FIELD_B].disabled = true;
            record[FIELD_C].disabled = true;
        } else if (toggleVal === "B") {
            record[FIELD_A].disabled = true;
            record[FIELD_B].disabled = false;
            record[FIELD_C].disabled = true;
        } else {
            record[FIELD_A].disabled = true;
            record[FIELD_B].disabled = true;
            record[FIELD_C].disabled = false;
        }
        return event;
    });
}());

Notes

Make sure to match the Field code of your fields, with the Field code written in the code.

 

Refer to the Tutorial page, on how to add scripts to your app.

Was this article helpful?
0 out of 0 found this helpful
Comments
Please sign in to leave a comment.