// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef EXT_DATEFIELD_H_
#define EXT_DATEFIELD_H_

#include <Wt/Ext/LineEdit>

namespace Wt {

  class WDate;

  namespace Ext {

/*! \class DateField Wt/Ext/DateField Wt/Ext/DateField
 *  \brief A form field for conveniently editing a date using a calendar popup.
 *
 * You can \link FormField::setValidator() set\endlink a
 * WDateValidator to specify in more detail the valid range, and the
 * client-side validation messages. When using a WDateValidator,
 * however, make sure to use the same \link
 * WDateValidator::setFormat() date format\endlink as the \link
 * setFormat() format\endlink used by the field.
 *
 * Here is a snapshot taken on 01/09/2007 (shown as today), and with
 * current value 12/09/2007 currently selected.
 * \image html ExtDateField-1.png "DateField"
 *
 * \sa Calendar, WDatePicker
 *
 * \ingroup ext
 */
class WT_EXT_API DateField : public LineEdit
{
public:
  /*! \brief Create a new date field.
   */
  DateField(WContainerWidget *parent = 0);

  /*! \brief Set the date format.
   *
   * The syntax of the format string is the same as used by
   * WDate::toString(const WString&).
   *
   * The default value is 'dd/MM/yyyy'.
   *
   * \sa format()
   */
  void setFormat(const WString& format);

  /*! \brief Return the date format.
   *
   * \sa setFormat()
   */
  const WString& format() const { return format_; }

  /*! \brief Set the date value.
   */
  void setDate(const WDate& date);

  /*! \brief Return the date value.
   *
   * When the date could not be parsed, an invalid date is returned
   * (for which WDate::isValid() returns false).
   */
  WDate date() const;

protected:
  virtual void createConfig(std::ostream& config);

private:
  WString format_;

  virtual std::string createJS(DomElement *inContainer);
};

  }
}

#endif // EXT_DATEFIELD_H_
