EmbAJAX
Simplistic framework for creating and handling displays and controls on a web page served by an embeddable device (Arduino or other microcontroller with Arduino support).
EmbAJAXValidatingTextInput.h
1 
22 #ifndef EMBAJAXVALIDATINGTEXTINPUT_H
23 #define EMBAJAXVALIDATINGTEXTINPUT_H
24 
25 #include "EmbAJAX.h"
26 
27 template<size_t SIZE> class EmbAJAXValidatingTextInput : public EmbAJAXTextInput<SIZE> {
28 public:
30  _attributes = EmbAJAXBase::null_string;
31  _placeholder = nullptr;
32  _pattern = nullptr;
33  }
34  void print() const override {
35  EmbAJAXBase::_driver->printFormatted("<input type=\"text\" id=", HTML_QUOTED_STRING(EmbAJAXTextInput<SIZE>::_id), " maxLength=", INTEGER_VALUE(SIZE-1),
36  " size=", INTEGER_VALUE(min(max(SIZE, (size_t) 11), (size_t) 41) - 1), " ", PLAIN_STRING(_attributes),
37  " onInput=\"doRequest(this.id, this.value); this.checkValidity();\"");
38  if (EmbAJAXTextInput<SIZE>::_value[0] != '\0') {
39  EmbAJAXBase::_driver->printAttribute("value", EmbAJAXTextInput<SIZE>::_value);
40  }
41  if (_placeholder != 0) {
42  EmbAJAXBase::_driver->printAttribute("placeholder", _placeholder);
43  }
44  if (_pattern != 0) {
45  EmbAJAXBase::_driver->printAttribute("pattern", _pattern);
46  }
47  EmbAJAXBase::_driver->printContent("/>");
48  }
50  void setPlaceholder(const char* placeholder) {
51  _placeholder = placeholder;
52  }
59  void setPattern(const char* pattern) {
60  _pattern = pattern;
61  }
69  void setCustomValidationAttributes(const char* attributes) {
70  _attributes = attributes;
71  }
72 private:
73  const char* _attributes;
74  const char* _placeholder;
75  const char* _pattern;
76 };
77 
78 #endif
void printAttribute(const char *name, const char *value)
Definition: EmbAJAX.cpp:137
A text input field.
Definition: EmbAJAX.h:386
Definition: EmbAJAXValidatingTextInput.h:27
void setPlaceholder(const char *placeholder)
Definition: EmbAJAXValidatingTextInput.h:50
void setCustomValidationAttributes(const char *attributes)
Definition: EmbAJAXValidatingTextInput.h:69
void setPattern(const char *pattern)
Definition: EmbAJAXValidatingTextInput.h:59
#define INTEGER_VALUE(X)
Definition: macro_definitions.h:56
#define PLAIN_STRING(X)
Definition: macro_definitions.h:54
#define HTML_QUOTED_STRING(X)
Definition: macro_definitions.h:49