I have a textbox and a table. I interact with the text that I send to the table. The problem I am facing is how to delete data in the textbox and table using a checkbox.
Hello @hah_hah
To assist you better, could you provide more specific details about your requirements? For example, are you looking to grey out the table when the checkbox is selected and after the data in the text field is deleted? Do you want the checkbox to clear once clicked on? The more details you provide, the better I can assist you.
Thank you for your attention.
I have data in a textbox which I send automatically to the table. Here is the code:
(function() {
"use strict";
function Row1(event) {
var record = event.record;
var table = record.tbl_P.value;
if (record.Approved1.length !== 0) {
table.push({
value: {
"P_txt_PartName": {
type: "SINGLE_LINE_TEXT",
value: record.T_PR_Part_Name_1.value
}
}
});
}
console.log("table", table);
}
//テーブルセット
function tableSet(event) {
var record = event.record;
var table = record.tbl_P.value;
table.length = 0;
Row1(event);
}
//テーブル非活性化
function tableDeactivation(event) {
var record = event.record;
for (var a in record['tbl_P'].value) {
record['tbl_P']['value'][a]['value']['P_txt_PartName']['disabled'] = true;
}
}
//レコード保存時
kintone.events.on(['app.record.create.submit', 'app.record.edit.submit'], function(event) {
tableSet(event);
return event;
});
//レコード入力時
kintone.events.on(['app.record.create.show', 'app.record.edit.show', 'app.record.create.change.tbl_P', 'app.record.edit.change.tbl_P'], function(event) {
tableDeactivation(event);
return event;
});
})();
Then, I want to automatically delete the data in that textbox using a checkbox. Is it possible to do that?
Because I have many textboxes, it will be a problem for me if I have to manually delete the textbox data.
Hello, @hah_hah,
Thank you for sharing the screenshots and explaining your objective.
Below is a basic script that clears data in text fields when the "Delete" option is selected in a checkbox field. Additionally, it removes the check from the "Delete" option once the data is cleared. Feel free to use it as a reference and modify it to suit your specific requirements.
(function() {
'use strict';
// Function to clear the Text and Text2 fields and uncheck the Delete option
function clearTextFields(event) {
var record = event.record;
// Check if the Delete option is checked in the Checkbox field
if (record.Checkbox.value.includes('Delete')) {
// Clear the Text and Text2 fields
record.Text.value = '';
record.Text2.value = '';
// Uncheck the Delete option
record.Checkbox.value = [];
}
return event;
}
// Register the event handler for changes in the Checkbox field
kintone.events.on(['app.record.create.change.Checkbox', 'app.record.edit.change.Checkbox'], clearTextFields);
})();
Thank you. This is very helpful to me.
May I ask another question if permitted,
Continuing from the issue above, I would like to add an auto number to a column. How can I do it, Meanwhile, the column data is filled using a textbox.
Thank you
Hello @hah_hah ,
Here's an example that automatically fills numbers sequentially in the text field within a table, and those text fields are greyed out.
(function() {
'use strict';
// Function to set autonumber for each row in the subtable
function setAutoNumber(event) {
var record = event.record;
var subTable = record.Table.value; // Corrected subtable field code
subTable.forEach(function(row, index) {
row.value.Autonumber.value = (index + 1).toString(); // Corrected autonumber field code
});
return event;
}
// Function to disable the Autonumber field
function disableAutoNumber(event) {
var record = event.record;
var subTable = record.Table.value; // Corrected subtable field code
subTable.forEach(function(row) {
row.value.Autonumber.disabled = true; // Disable the Autonumber field
});
return event;
}
// Function to set autonumber and disable the fields
function updateAndDisable(event) {
setAutoNumber(event);
disableAutoNumber(event);
return event;
}
// Event handlers for when rows are added or removed
var changeEvents = [
'app.record.create.change.Table',
'app.record.edit.change.Table'
];
// Event handlers for when the form is shown
var showEvents = [
'app.record.create.show',
'app.record.edit.show'
];
// Register the event handlers
kintone.events.on(changeEvents, updateAndDisable);
kintone.events.on(showEvents, updateAndDisable);
})();
Thank you very much, thanks to you my Kintone program is running smoothly