Actions within Rich text field

170 views
Skip to first unread message

karam mohammed 1

unread,
Jul 24, 2025, 7:39:18 PM7/24/25
to mementodatabase
I asked if it’s possible to make each button in a rich text field perform specific actions, like changing the value of a field.

I need this as I organize linked entries in table and I need to put bottom to edit each linked entry beside each one 
I do this as I noticed that hiding linked enteries make opening parent entry faster



This is Example . Thanks in advance

(function () {
    var e = entry();
    var outputField = "Test";

    var html = ''
        + '<style>'
        + 'table.simple { width: 100%; border-collapse: collapse; direction: ltr; font-family: sans-serif; font-size: 14px; }'
        + 'th, td { border: 1px solid #ccc; padding: 6px; text-align: center; }'
        + 'th { background: #c8e6c9; }'
        + '.btn { padding: 6px 12px; margin: 2px; background: #4CAF50; color: white; border-radius: 4px; font-size: 14px; text-decoration: none; cursor: pointer; }'
        + '</style>'

        + '<table class="simple">'
        + '<thead><tr><th>Button</th><th>Action</th></tr></thead>'
        + '<tbody>'
        + '<tr><td>A</td><td><button class="btn">A</button></td></tr>'
        + '<tr><td>B</td><td><button class="btn">B</button></td></tr>'
        + '<tr><td>C</td><td><button class="btn">C</button></td></tr>'
        + '</tbody>'
        + '</table>';

    e.set(outputField, html);
})();

Mmm

unread,
Aug 3, 2025, 6:57:31 AM8/3/25
to mementodatabase
Автор удалил тему "Diamond layoot".
Вероятно ответ найден.

Мой вариант относится к удаленной теме "Diamond layoot".

Для решения нужно добавить в начало группы элементов регулируемый по ширине текстовый элемент.
В каждой строке должно быть четыре элемента: текст, чекбокс, текст, чекбокс.

В примере используется не ромб, а параболы.

К сожалению, я не знаю, как получить ширину диалогового окна. 
Кроме того, она будет зависеть от характеристик экрана устройства.
Поэтому настройки параметров выполнены подбором вручную:

— отступ от левого края:

var indent = 20;
        
— интервал между параболами:

var interval = 80;

— изгиб параболы – аргумент "step",

— общая ширина – аргумент "width",

— отступ разделителя от левого края выполнен добавлением табулятора "\t" к линии,

— длина линии изменяется количеством повторов "-".

После подбора параметров, их нужно перенести в основной скрипт.

Облачное использование несколькими пользователями с разными экранами требует доработки кода и создание наборов параметров.

Шаблон с примером:

пятница, 25 июля 2025 г. в 02:39:18 UTC+3, kara...@gmail.com:
IC__03082025.jpg

karam mohammed 1

unread,
Aug 3, 2025, 7:07:24 AM8/3/25
to mementodatabase

Your script worked perfectly—thank you so much! I had deleted the topic after it remained unanswered for a long time, and after many attempts, I eventually managed to solve it myself. so It deleted it after I solved it . I really appreciate your help!

karam mohammed 1

unread,
May 5, 2026, 6:10:05 AMMay 5
to mementodatabase

Is there a way to solve my main issue?

I want to create buttons using HTML inside Memento, where each button changes its color when pressed.

Also, I need another action that can read the current colors (or states) of these buttons and save those values into fields.

Thanks in advance

Mmm

unread,
May 5, 2026, 12:53:05 PM (14 days ago) May 5
to mementodatabase
Выполнить скрипт кнопкой в поле форматированный текст нельзя или я не знаю.

Можете пронумеровать свои записи в поле форматированный текст.
В дальнейшем выполнять нужные действия с любым элементом обычным скриптом действие с аргументом (номер элемента).
Массив ID связанных записей (например, в формате JSON) хранить в скрытом поле JS. В поле JS включить выполнение в реальном времени или принудительно обновлять непосредственно перед выполнением скрипта с помощью recalc().

Пример поля JS:

let list = field(linked entries);
if (list.length > 0) {
    let objects = list.map(a => return {ide: a.id});
    JSON.stringify(objects);
} else {
    null;
}

Связанная запись в скрипте определяется по ID с индексом элемента равном аргумент минус 1.

Пример скрипта действие в карточке записи с аргументом целое число:

let index = arg('please indicate the line number:');

let e = entry(); 
e.recalc();
let json = e.field('ide_json');

if (json) {
    let lbn = libByName('ABCDE');
    let items = JSON.parse(json);

    try {
        let item = items[index - 1];
        let obj = lbn.findById(item.ide);
        obj.show();//другое действие

    } catch (err) {
        message('Entry №' + index + ' not found.');
    }
}

Все в целом позволит выполнить нужные действия без html–кнопки напротив каждой строки.

вторник, 5 мая 2026 г. в 13:10:05 UTC+3, kara...@gmail.com:

karam mohammed 1

unread,
May 5, 2026, 7:37:43 PM (14 days ago) May 5
to mementodatabase

Thank you very much for your help and for taking the time to explain your solution. I really appreciate it.

However, for my specific use case, the approach feels a bit too complex and not very practical, since I was hoping for a simpler and more direct interaction (like selecting directly from a visual dental chart).

Thanks again for your support and effort 🙏

Reply all
Reply to author
Forward
0 new messages