Skip to content

Commit

Permalink
Toggle bool input while custom tab is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
parthy007 committed Apr 12, 2024
1 parent 26bda6a commit 25819a4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions frontend/src/TooljetDatabase/Forms/RowForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ const RowForm = ({ onCreate, onClose }) => {
return { value: '', checkboxValue: false, disabled: false };
}
if (item.column_default !== null) {
return { value: item.column_default || '', checkboxValue: item.column_default, disabled: true };
return {
value: item.column_default || '',
checkboxValue: item.column_default === 'true' ? true : false,
disabled: true,
};
} else if (item.constraints_type.is_not_null === false) {
return { value: '', checkboxValue: false, disabled: false };
}
Expand All @@ -56,6 +60,8 @@ const RowForm = ({ onCreate, onClose }) => {
});
return data;
});
// console.log("Columns: ",columns)
console.log('InputValues: ', inputValues);

const handleTabClick = (index, tabData, defaultValue, nullValue, columnName, dataType) => {
const newActiveTabs = [...activeTab];
Expand Down Expand Up @@ -103,12 +109,17 @@ const RowForm = ({ onCreate, onClose }) => {
};

const handleCheckboxChange = (index, value, columnName) => {
console.log('InputValues: ', inputValues);
console.log('ColumnName: ', columnName);

const newInputValues = [...inputValues];
newInputValues[index] = {
value: inputValues[index].value,
checkboxValue: !inputValues[index].checkboxValue,
disabled: inputValues[index].disabled,
};

console.log('NewInputValues', newInputValues);
setInputValues(newInputValues);
setData({ ...data, [columnName]: value });
};
Expand Down Expand Up @@ -183,7 +194,7 @@ const RowForm = ({ onCreate, onClose }) => {
className="form-check-input"
data-cy={`${String(columnName).toLocaleLowerCase().replace(/\s+/g, '-')}-check-input`}
type="checkbox"
checked={inputValues[index].checkboxValue === 'true' ? true : false}
checked={inputValues[index].checkboxValue}
onChange={(e) => {
if (!inputValues[index].disabled) handleCheckboxChange(index, e.target.checked, columnName);
}}
Expand Down

0 comments on commit 25819a4

Please sign in to comment.