Avatar

Read-Only Fields

Dontae Jones

I have total of 10 fields I would like to make read-only when the record is in Edit mode. These fields are populated with imported data that users should not be able to edit.

Is there way to achieve this in a Kintone app? If so, what are the steps to setting this up?

Follow 2 followers
1

1 comment

Avatar
Sean Tachibana 0 votes

Hi Dontae,

The following code should disable for editing and make the fields view only.
When creating and editing the record, the field "['item_number']" is disabled.
Please check and see if this helps you achieve the desired process.

(function() {
"use strict";
kintone.events.on(['app.record.create.show',
   'app.record.edit.show'], function(event) {

// Get record information from event
var record = event.record;

//Fields cannot be edited
record['item_number'].disabled = true;

return event;
});
})();

Also, the code below allows you to disable editing even fields that are in tables.
The timings are when the record is being created, edited, and after the record list page is displayed on the desktop.

(function() {
"use strict";

// All fields are disabled for editing.
function field_edit_disable(event){
var record = event.record;
for (var property in record){
var field_obj = record[property]
if (field_obj['type'] == 'SUBTABLE'){
for (var sub_table_value in field_obj['value']){
var sub_table_value_obj = field_obj['value'][sub_table_value];
for (var sub_table_field in sub_table_value_obj['value']){
sub_table_value_obj['value'][sub_table_field]['disabled'] = true;
}
}
}else{
record[property]['disabled'] = true;
}
}
return event;
}

// Summarize events for list, new, and detail editing
var edit_events = [
'app.record.index.edit.show',
'app.record.create.show',
'app.record.edit.show'
]

// Summary editing events
kintone.events.on(edit_events, function(event) {
return field_edit_disable(event);
});

})();

Following are some of the triggers for your reference; please take a look.

Record Edit Event:
https://developer.kintone.io/hc/en-us/articles/213149017-Record-Edit-Event

Record Create Event:
https://developer.kintone.io/hc/en-us/articles/213149077-Record-Create-Event

Record List Event:
https://developer.kintone.io/hc/en-us/articles/212494758-Record-List-Event

Please try out both and see whichever works for you best.
Hopefully, this helps.

0
Comment actions Permalink