Project

General

Profile

Bug #4733 ยป suggestionPopup.C

Yoika Ghysens, 04/18/2016 06:56 PM

 
#include <Wt/WApplication>
#include <Wt/WLineEdit>
#include <Wt/WSuggestionPopup>
#include <Wt/WContainerWidget>
#include <Wt/WText>
#include <Wt/WLength>
#include <Wt/WGridLayout>

class FormApplication : public Wt::WApplication
{
public:
FormApplication(const Wt::WEnvironment &env);
private:
int rowCount = 3;
};

FormApplication::FormApplication(const Wt::WEnvironment &env) : Wt::WApplication(env)
{
Wt::WSuggestionPopup::Options contactOptions;
contactOptions.highlightBeginTag = "<span class=\"highlight\">";
contactOptions.highlightEndTag = "</span>";
contactOptions.listSeparator = ',';
contactOptions.whitespace = " \\n";
contactOptions.wordSeparators = "-., \"@\\n;";
contactOptions.appendReplacedText = ", ";

Wt::WContainerWidget *container = new Wt::WContainerWidget(root());
Wt::WGridLayout *layout = new Wt::WGridLayout(container);
Wt::WSuggestionPopup *popup = new Wt::WSuggestionPopup(contactOptions, container);
Wt::WLineEdit *lineEdit = new Wt::WLineEdit();
layout->addWidget(lineEdit, 1, 1);
Wt::WLength *length = new Wt::WLength(500);
lineEdit->setWidth(*length);
popup->forEdit(lineEdit, Wt::WSuggestionPopup::DropDownIcon);
Wt::WLineEdit *lineEdit2 = new Wt::WLineEdit();
layout->addWidget(lineEdit2, 2, 1);
lineEdit->changed().connect(std::bind([=](){
layout->addWidget(new Wt::WText("Changed emitted"), rowCount, 1);
rowCount++;
}));

popup->addSuggestion("John Tech <techie@mycompany.com>");
popup->addSuggestion("Johnny Cash <cash@mycompany.com>");
popup->addSuggestion("John Rambo <rambo@mycompany.com>");
popup->addSuggestion("Johanna Tree <johanna@mycompany.com>");
}

Wt::WApplication *createApplication(const Wt::WEnvironment &env)
{
return new FormApplication(env);
}

int main(int argc, char **argv)
{
return Wt::WRun(argc, argv, &createApplication);
}
    (1-1/1)