s00500 / ESPUI

A simple web user interface library for ESP32 and ESP8266

Home Page:https://valencia.lbsfilm.at/midterm-presentation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Just a question...

nodoubtman opened this issue · comments

Hello, i love your library, i use it everyday.
I only rely on this library, but i would like to know how to add or replace option in the select.

Here's my code:

``
uint16_t imageNouvelleSelect;
imageNouvelleSelect = ESPUI.addControl( ControlType::Select, "IMAGE SELECT&#x1F467", F(""), COLOR_TURQUOISE, tabNouvellesHeadlines, &gererNouvelleImage);

#define MAX_TOP_NEWS 10
typedef struct {
char title[210];
char urlToImg[150];
} newsTopApiOrgStruct;
newsTopApiOrgStruct newsApiTopDatas[MAX_TOP_NEWS];
// newsApiTopDatas[i].title
// newsApiTopDatas[i].urlToImg

#define MAX_TOP_NEWS

void Ajouter_Images_News_Dans_Select() {

for ( int i = 0; i < MAX_TOP_NEWS; i++) {

if ( strcmp(newsApiTopDatas[i].urlToImg, "N/A") != 0)
  ESPUI.addControl( ControlType::Option, newsApiTopDatas[i].title, String(newsApiTopDatas[i].urlToImg), COLOR_WETASPHALT, imageNouvelleSelect);
yield();

}

ESPUI.updateSelect(imageNouvelleSelect, newsApiTopDatas[0].urlToImg);
ESPUI.jsonDom(0);
}
``
Thanks.
Marc.

Hi, did you manage to solve your problem?

I didnt solve it.
No one answered.
Marc.

You only waited a day and a half. We all have real jobs you know ;)

I don't happen to have a ready-made example of dynamic options, but I think it should work fine.

Help us to help you, what is wrong with your code? As far as I can see your code should work, my only concern would be with the strings/structs used as titles. If they are declared in a function then the ESPUI structures may take references from the stack which become invalid when the function returns. Are they global scope?

Yes they are globals.

So you haven't said what happens, or doesn't.

The problem is that i cannot add options qfter the UI started.

But your code doesn't appear to /try/ to add options after the UI has started?

The problem yes... see addControl and the for loop

One options added i cannot add more then..

Hang on I'm confused. You say that newsApiTopDatas is defined at global scope, but you show it interleaved with code, so it can't be. Can you include a minimal working example?

The problem is that i cannot add options after the UI started.

That is possible, but I recall that you'll need to refresh the browser to see the newly loaded options. I think your "ESPUI.jsonDom(0);" might have been an attempt to do just that. Try a browser refresh instead.

  • Thomas

So ESPUI.jsonReload() will trigger a refresh and reload of the entire UI. ESPUI.jsonDom(0) will resend the UI but keep whatever is already in the browser, potentially resulting in duplicate controls.