Hello. Is there any solution to disable by condition inline edit for single field(column) in asingle row for list view table ?
No.
Only if you customize code. Note that the inline edit mechanisms are different for v7 and for v8, and that even if you’re running v8, some modules are using the legacy v7 system (e.g. Events).
Thanks a lot, using v7
Are you a developer?
Would you prefer changing this in JS (front-end) or in PHP (back-end)?
developer. i think it is right to implement logick with PHP
The first call into the backend happens at
modules/Home/controller.php
See the browser’s network tab to find the request being made. If it says action=saveHTMLField, for example, then the controller action is called action_saveHTMLField
Then that will call functions from
include/InlineEditing/InlineEditing.php
The front-end is in
include/InlineEditing/inlineEditing.js
This is a tough nut to crack. I normally just make the field globally non in-line edit and then modify editviewdefs to determine if the user can edit the field in edit view.
Following, if there is a good solution for this.
My solution.
Edit view.list.php
class SomeBeanViewList extends ViewList
{
// 1.override default method like this
public function listViewProcess()
{
parent::listViewProcess();
$this->injectScript();
}
private function injectScript()
{
// 2.extract ids
$dataIds = array_column($this->lv->data['data'], 'ID');
// 3.leave ids that have to be disabled
$idsDoNotEdit = json_encode($this->bean->processData($dataIds));
//4.inject JS script to page
echo '<script>SUGAR.inlineEditDisabled = '. $idsDoNotEdit .';
const colName = "status";
SUGAR.inlineEditDisabled.forEach(id => {
//5. find column and override default click event
document.querySelector(`.listview-checkbox[value=${id}]`).parentNode.parentNode.querySelector(`td[field=${colName}]`).querySelector("div.inlineEditIcon").addEventListener("click", e => {
e.preventDefault();
e.stopPropagation();
alert(SUGAR.language.translate("SomeBean", "LBL_YOU_CAN_NOT_EDIT_THIS_FIELD"));
})
});
</script>';
}
}
Why not put that logic inside inlineEditing.js?
i don`t want to modify core files
i think it is possible to include custom script in metdata file
Correct.
Ok. I have extensive changes in the inlineEditing files, so I am no longer bothered with it being a core change, but you are right, that decision to change core files has down-sides, so it shouldn’t be taken except where unavoidable.
If you had decided to do the customizations in the back-end, these would be possible using a custom controller, without changing core files.
if it is not difficult for you to give an example of such an implementation. I don’t quite understand how to implement this
custom/modules/Home/controller.php
<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
require_once 'modules/Home/controller.php';
class CustomHomeController extends HomeController
public function action_saveHTMLField()
{
...
}
}