1 #include <Wt/WCalendar.h> 2 #include <Wt/WDate.h> 3 #include <Wt/WTimeEdit.h> 4 #include <Wt/WLabel.h> 5 #include <Wt/WPushButton.h> 6 #include <Wt/WText.h> 7 #include <Wt/WTemplate.h> 8 #include <Wt/WString.h> 9 10 SAMPLE_BEGIN(TimeEdit) 11 auto form = std::make_unique<Wt::WTemplate>(Wt::WString::tr("timeEdit-template")); 12 form->addFunction("id", &Wt::WTemplate::Functions::id); 13 14 auto te1 = form->bindWidget("from", std::make_unique<Wt::WTimeEdit>()); 15 form->bindString("from-format", te1->format()); 16 te1->setTime(Wt::WTime::currentTime()); 17 18 auto te2 = form->bindWidget("to", std::make_unique<Wt::WTimeEdit>()); 19 #ifndef WT_TARGET_JAVA 20 te2->setFormat("h:mm:ss.zzz AP"); 21 #else 22 te2->setFormat("h:mm:ss.SSS a"); 23 #endif 24 te2->setTime(Wt::WTime::currentTime().addSecs(60*15)); 25 form->bindString("to-format", te2->format()); 26 27 auto button = form->bindWidget("save", std::make_unique<Wt::WPushButton>("Save")); 28 29 auto out = form->bindWidget("out", std::make_unique<Wt::WText>()); 30 __anona6e7a47b0102null31te1->changed().connect([=] { 32 if (te1->validate() == Wt::ValidationState::Valid) { 33 out->setText("Time picker 1 is changed."); 34 } 35 }); 36 __anona6e7a47b0202null37te2->changed().connect([=] { 38 if (te2->validate() == Wt::ValidationState::Valid) { 39 out->setText("Time picker 2 is changed."); 40 } 41 }); 42 __anona6e7a47b0302null43button->clicked().connect([=] { 44 if (te1->text().empty() || te2->text().empty()) 45 out->setText("You should enter two times!"); 46 else { 47 long secs = te1->time().secsTo(te2->time()) + 1; 48 if (secs <= 60*10) 49 out->setText("This is a really small range of time"); 50 else 51 out->setText 52 (Wt::WString("So, you want your package to be delivered between " 53 "{1} and {2}?") 54 .arg(te1->time().toString()) 55 .arg(te2->time().toString())); 56 } 57 }); 58 59 SAMPLE_END(return std::move(form)) 60 61