Skip to content

Commit ede2471

Browse files
YoikaGRockinRoel
authored andcommitted
Specialized WFormDelegate for WDateTime
This delegate will create a WLineEdit for representing WDateTime values in WTemplateFormView.
1 parent f3cce68 commit ede2471

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Wt/Form/WFormDelegate.C

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
#include <Wt/WCheckBox.h>
99
#include <Wt/WDateEdit.h>
10+
#include <Wt/WDateTime.h>
1011
#include <Wt/WDateValidator.h>
1112
#include <Wt/WIntValidator.h>
1213
#include <Wt/WLineEdit.h>
14+
#include <Wt/WLocale.h>
1315
#include <Wt/WLogger.h>
1416
#include <Wt/WTimeEdit.h>
1517
#include <Wt/WTimeValidator.h>
@@ -80,6 +82,24 @@ void WFormDelegate<Wt::WTime, void>::updateModelValue(Wt::WFormModel *model, Wt:
8082
}
8183
}
8284

85+
WFormDelegate<Wt::WDateTime, void>::WFormDelegate()
86+
: WAbstractFormDelegate()
87+
{
88+
}
89+
90+
std::unique_ptr<Wt::WWidget> WFormDelegate<Wt::WDateTime, void>::createFormWidget()
91+
{
92+
return std::make_unique<Wt::WLineEdit>();
93+
}
94+
95+
void WFormDelegate<Wt::WDateTime, void>::updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit)
96+
{
97+
if (!edit->valueText().empty()) {
98+
Wt::WDateTime value = Wt::WDateTime::fromString(edit->valueText(), Wt::WLocale::currentLocale().dateTimeFormat());
99+
model->setValue(field, value);
100+
}
101+
}
102+
83103
WFormDelegate<bool,void>::WFormDelegate()
84104
: WAbstractFormDelegate()
85105
{

src/Wt/Form/WFormDelegate.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ class WT_API WFormDelegate<Wt::WTime, void> : public WAbstractFormDelegate
8585
void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override;
8686
};
8787

88+
/*! \brief Form delegate class for WDateTime
89+
*
90+
* This will create a WLineEdit to display the WDateTime value
91+
* in the View
92+
*/
93+
template<>
94+
class WT_API WFormDelegate<Wt::WDateTime, void> : public WAbstractFormDelegate
95+
{
96+
public:
97+
/*! \brief Create a form delegate
98+
*/
99+
WFormDelegate();
100+
101+
/*! \brief Create a WLineEdit to be used in the View
102+
*/
103+
std::unique_ptr<Wt::WWidget> createFormWidget() override;
104+
105+
/*! \brief Update the value in the Model
106+
*
107+
* In the future this implementation will change to return a dedicated widget
108+
* for WDateTime objects.
109+
*/
110+
void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override;
111+
};
112+
88113
/*! \brief Form delegate class for boolean
89114
*
90115
* This will create a WCheckBox to display the boolean value

0 commit comments

Comments
 (0)