Form.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // This may look like C code, but it's really -*- C++ -*-
  2. /*
  3. * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
  4. *
  5. * See the LICENSE file for terms of use.
  6. */
  7. #ifndef FORM_H_
  8. #define FORM_H_
  9. #include <Wt/WTable>
  10. using namespace Wt;
  11. namespace Wt {
  12. class WContainerWidget;
  13. class WText;
  14. class WTextArea;
  15. class WLineEdit;
  16. class WComboBox;
  17. class WFormWidget;
  18. class WDatePicker;
  19. }
  20. /**
  21. * @addtogroup formexample
  22. */
  23. /*@{*/
  24. /*!\brief A simple Form.
  25. *
  26. * Shows how a simple form can made, with an emphasis on how
  27. * to handle validation.
  28. */
  29. class Form : public WTable
  30. {
  31. public:
  32. /*!\brief Instantiate a new form.
  33. */
  34. Form(WContainerWidget *parent = 0);
  35. private:
  36. /*!\brief The user selected a new country: adjust the cities combo box.
  37. */
  38. void countryChanged();
  39. /*!\brief Submit the form.
  40. */
  41. void submit();
  42. void createUI();
  43. WContainerWidget *feedbackMessages_;
  44. WLineEdit *nameEdit_;
  45. WLineEdit *firstNameEdit_;
  46. WComboBox *countryEdit_;
  47. WComboBox *cityEdit_;
  48. WDateEdit *birthDateEdit_;
  49. WLineEdit *childCountEdit_;
  50. WLineEdit *weightEdit_;
  51. WTextArea *remarksEdit_;
  52. /*!\brief Add a validation feedback for a field
  53. */
  54. void addValidationStatus(int row, WFormWidget *field);
  55. /*!\brief Validate the form, and return whether succesfull.
  56. */
  57. bool validate();
  58. /*!\brief Validate a single form field.
  59. *
  60. * Checks the given field, and appends the given text to the error
  61. * messages on problems.
  62. */
  63. bool checkValid(WFormWidget *edit, const WString& text);
  64. };
  65. /*@}*/
  66. #endif // FORM_H_