Skip to content

Commit 44de9df

Browse files
committed
fix: button events edit was always saving first entry in a list
closes #198
1 parent d5a4eb0 commit 44de9df

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

resources/html/js/ui.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,7 @@
25382538
{
25392539
"id":"lamppwr",
25402540
"html":"input",
2541-
"label":"Device On/Off",
2541+
"label":"Trigger only when device is On",
25422542
"type":"checkbox"
25432543
},
25442544
{

src/interface.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,23 @@ void page_button_setup(Interface *interf, JsonVariantConst data, const char* act
295295
interf->uidata_pick( "lampui.settings.button" );
296296
interf->json_frame_flush();
297297

298-
// call setter with no data, it will publish existing config values if any
298+
// call setter with no data, it will publish current gpio configuration values, if any
299299
getset_button_gpio(interf, {}, NULL);
300+
// call setter with no data, it will publish current encoder gpio configuration values, if any
300301
getset_encoder_gpio(interf, {}, NULL);
301302

302303
JsonDocument doc;
303304
if (embuifs::deserializeFile(doc, T_benc_cfg)) return; // config is missing, bad
304305
JsonArray bevents( doc[T_btn_events] );
305306

306307
interf->json_frame_interface();
307-
interf->json_section_begin("button_events_list");
308+
// replace placeholder section in template with a list of button events config
309+
interf->json_section_begin("button_events_list", P_EMPTY, false, false, false, true);
308310

309311
int cnt = 0;
310312
for (JsonVariant value : bevents) {
311313
JsonObject obj = value.as<JsonObject>();
312-
interf->json_section_begin(String("sec") + cnt, (const char*)0, false, false, true );
314+
interf->json_section_begin(String("sec") + cnt, P_EMPTY, false, false, true );
313315
interf->checkbox(P_EMPTY, obj[T_enabled], "Active");
314316
interf->checkbox(P_EMPTY, obj[T_pwr], "Pwr On/Off");
315317

@@ -400,7 +402,7 @@ void page_button_evt_save(Interface *interf, JsonVariantConst data, const char*
400402
JsonDocument doc;
401403
if (embuifs::deserializeFile(doc, T_benc_cfg)) doc.clear();
402404
JsonArray bevents( doc[T_btn_events] );
403-
int idx = data.as<int>();
405+
uint idx = data[P_idx];
404406
JsonObject obj = idx < bevents.size() ? bevents[idx] : bevents.add<JsonObject>();
405407

406408
JsonObjectConst jo(data);
@@ -412,7 +414,8 @@ void page_button_evt_save(Interface *interf, JsonVariantConst data, const char*
412414

413415
button_configure_events(doc[T_btn_events]);
414416

415-
if (interf) page_button_setup(interf, {}, NULL);
417+
if (interf)
418+
page_button_setup(interf, {}, NULL);
416419
}
417420

418421
// DFPlayer related pages

0 commit comments

Comments
 (0)