Added lots of input related helper methods to HTMLBuilder.

This commit is contained in:
Relintai 2021-11-16 13:35:55 +01:00
parent 123866edfa
commit 9c53d521b4
2 changed files with 602 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "html_builder.h" #include "html_builder.h"
#include "core/string.h"
HTMLTag *HTMLTag::str(const String &str) { HTMLTag *HTMLTag::str(const String &str) {
result += " " + str; result += " " + str;
@ -48,6 +49,42 @@ HTMLTag *HTMLTag::value(const String &val) {
return this; return this;
} }
HTMLTag *HTMLTag::accept(const String &val) {
attrib("accept", val);
return this;
}
HTMLTag *HTMLTag::src(const String &val) {
attrib("src", val);
return this;
}
HTMLTag *HTMLTag::alt(const String &val) {
attrib("alt", val);
return this;
}
HTMLTag *HTMLTag::autocomplete(const String &val) {
attrib("autocomplete", val);
return this;
}
HTMLTag *HTMLTag::inputmode(const String &val) {
attrib("inputmode", val);
return this;
}
HTMLTag *HTMLTag::list(const String &val) {
attrib("list", val);
return this;
}
HTMLTag *HTMLTag::checked(const bool val) { HTMLTag *HTMLTag::checked(const bool val) {
if (val) { if (val) {
result += " checked"; result += " checked";
@ -56,6 +93,116 @@ HTMLTag *HTMLTag::checked(const bool val) {
return this; return this;
} }
HTMLTag *HTMLTag::autofocus(const bool val) {
if (val) {
result += " autofocus";
}
return this;
}
HTMLTag *HTMLTag::disabled(const bool val) {
if (val) {
result += " disabled";
}
return this;
}
HTMLTag *HTMLTag::multiple(const bool val) {
if (val) {
result += " multiple";
}
return this;
}
HTMLTag *HTMLTag::required(const bool val) {
if (val) {
result += " required";
}
return this;
}
HTMLTag *HTMLTag::max(const String &val) {
attrib("max", val);
return this;
}
HTMLTag *HTMLTag::min(const String &val) {
attrib("min", val);
return this;
}
HTMLTag *HTMLTag::step(const String &val) {
attrib("step", val);
return this;
}
HTMLTag *HTMLTag::step_any() {
attrib("step", "any");
return this;
}
HTMLTag *HTMLTag::minlength(const int val) {
attrib("minlength", String::num(val));
return this;
}
HTMLTag *HTMLTag::minlength(const String &val) {
attrib("minlength", val);
return this;
}
HTMLTag *HTMLTag::maxlength(const int val) {
attrib("maxlength", String::num(val));
return this;
}
HTMLTag *HTMLTag::maxlength(const String &val) {
attrib("maxlength", val);
return this;
}
HTMLTag *HTMLTag::size(const int val) {
attrib("size", String::num(val));
return this;
}
HTMLTag *HTMLTag::size(const String &val) {
attrib("size", val);
return this;
}
HTMLTag *HTMLTag::width(const int val) {
attrib("width", String::num(val));
return this;
}
HTMLTag *HTMLTag::width(const String &val) {
attrib("width", val);
return this;
}
HTMLTag *HTMLTag::height(const int val) {
attrib("height", String::num(val));
return this;
}
HTMLTag *HTMLTag::height(const String &val) {
attrib("height", val);
return this;
}
HTMLTag *HTMLTag::method(const String &val) { HTMLTag *HTMLTag::method(const String &val) {
attrib("method", val); attrib("method", val);
@ -221,6 +368,47 @@ HTMLTag *HTMLTag::itweek() {
return this; return this;
} }
HTMLTag *HTMLTag::inputmode_none() {
attrib("inputmode", "none");
return this;
}
HTMLTag *HTMLTag::inputmode_text() {
attrib("inputmode", "text");
return this;
}
HTMLTag *HTMLTag::inputmode_decimal() {
attrib("inputmode", "decimal");
return this;
}
HTMLTag *HTMLTag::inputmode_numeric() {
attrib("inputmode", "numeric");
return this;
}
HTMLTag *HTMLTag::inputmode_tel() {
attrib("inputmode", "tel");
return this;
}
HTMLTag *HTMLTag::inputmode_search() {
attrib("inputmode", "search");
return this;
}
HTMLTag *HTMLTag::inputmode_email() {
attrib("inputmode", "email");
return this;
}
HTMLTag *HTMLTag::inputmode_url() {
attrib("inputmode", "url");
return this;
}
HTMLTag *HTMLTag::attrib(const String &attr, const String &val) { HTMLTag *HTMLTag::attrib(const String &attr, const String &val) {
result += " " + attr + "=\"" + val + "\""; result += " " + attr + "=\"" + val + "\"";
@ -1982,6 +2170,353 @@ HTMLTag *HTMLBuilder::input_week() {
return tag.start("input")->itweek(); return tag.start("input")->itweek();
} }
HTMLTag *HTMLBuilder::input_button(const String &name, const String &value, const String &cls, const String &id) {
HTMLTag *t = input_button();
t->name(name);
if (value != "") {
t->value(value);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
HTMLTag *HTMLBuilder::input_checkbox(const String &name, const String &value, const String &cls, const String &id) {
HTMLTag *t = input_checkbox();
t->name(name);
if (value != "") {
t->value(value);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
HTMLTag *HTMLBuilder::input_color(const String &name, const String &value, const String &cls, const String &id) {
HTMLTag *t = input_color();
t->name(name);
if (value != "") {
t->value(value);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
HTMLTag *HTMLBuilder::input_date(const String &name, const String &value, const String &cls, const String &id, const String &date_min, const String &date_max, const String &date_step) {
HTMLTag *t = input_date();
t->name(name);
if (value != "") {
t->value(value);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
if (date_min != "") {
t->min(date_min);
}
if (date_max != "") {
t->max(date_max);
}
if (date_step != "") {
t->step(date_step);
}
return t;
}
HTMLTag *HTMLBuilder::input_datetime_local(const String &name, const String &value, const String &cls, const String &id, const String &date_min, const String &date_max, const String &date_step) {
HTMLTag *t = input_datetime_local();
t->name(name);
if (value != "") {
t->value(value);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
if (date_min != "") {
t->min(date_min);
}
if (date_max != "") {
t->max(date_max);
}
if (date_step != "") {
t->step(date_step);
}
return t;
}
HTMLTag *HTMLBuilder::input_email(const String &name, const String &value, const String &placeholder, const String &cls, const String &id) {
HTMLTag *t = input_email();
t->name(name);
if (value != "") {
t->value(value);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
if (placeholder != "") {
t->placeholder(placeholder);
}
return t;
}
HTMLTag *HTMLBuilder::input_file(const String &name, const String &accept, const String &cls, const String &id) {
HTMLTag *t = input_email();
t->name(name);
if (accept != "") {
t->accept(accept);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
HTMLTag *HTMLBuilder::input_image(const String &name, const String &src, const String &alt, const String &cls, const String &id, const int width, const int height) {
HTMLTag *t = input_image();
t->name(name);
if (src != "") {
t->src(src);
}
if (alt != "") {
t->alt(alt);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
if (width != 0) {
t->width(width);
}
if (height != 0) {
t->height(height);
}
return t;
}
HTMLTag *HTMLBuilder::input_month(const String &name, const String &cls, const String &id) {
HTMLTag *t = input_month();
t->name(name);
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
HTMLTag *HTMLBuilder::input_number(const String &name, const String &vmin, const String &vmax, const String &cls, const String &id) {
HTMLTag *t = input_number();
t->name(name);
if (vmin != "") {
t->min(vmin);
}
if (vmax != "") {
t->max(vmax);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
HTMLTag *HTMLBuilder::input_password(const String &name, const String &value, const String &placeholder, const String &cls, const String &id, const String &minlength, const String &maxlength, const String &size) {
HTMLTag *t = input_password();
t->name(name);
if (value != "") {
t->value(value);
}
if (placeholder != "") {
t->placeholder(placeholder);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
if (minlength != "") {
t->minlength(minlength);
}
if (maxlength != "") {
t->maxlength(maxlength);
}
if (size != "") {
t->size(size);
}
return t;
}
HTMLTag *HTMLBuilder::input_radio(const String &name, const String &value, const String &cls, const String &id) {
HTMLTag *t = input_password();
t->name(name);
if (value != "") {
t->value(value);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
HTMLTag *HTMLBuilder::input_range(const String &name, const String &value, const String &vmin, const String &vmax, const String &vstep, const String &cls, const String &id) {
HTMLTag *t = input_range();
t->name(name);
if (value != "") {
t->value(value);
}
if (vmin != "") {
t->min(vmin);
}
if (vmax != "") {
t->max(vmax);
}
if (vstep != "") {
t->step(vstep);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
HTMLTag *HTMLBuilder::input_reset(const String& name, const String& value, const String& cls, const String& id) {
HTMLTag *t = input_reset();
t->name(name);
if (value != "") {
t->value(value);
}
if (cls != "") {
t->cls(cls);
}
if (id != "") {
t->id(id);
}
return t;
}
void HTMLBuilder::f() { void HTMLBuilder::f() {
write_tag(); write_tag();

View File

@ -19,7 +19,36 @@ public:
HTMLTag *name(const String &val); HTMLTag *name(const String &val);
HTMLTag *content(const String &val); HTMLTag *content(const String &val);
HTMLTag *value(const String &val); HTMLTag *value(const String &val);
HTMLTag *accept(const String &val);
HTMLTag *src(const String &val);
HTMLTag *alt(const String &val);
HTMLTag *autocomplete(const String &val);
HTMLTag *inputmode(const String &val);
HTMLTag *list(const String &val);
HTMLTag *checked(const bool val = true); HTMLTag *checked(const bool val = true);
HTMLTag *autofocus(const bool val = true);
HTMLTag *disabled(const bool val = true);
HTMLTag *multiple(const bool val = true);
HTMLTag *required(const bool val = true);
HTMLTag *max(const String &val);
HTMLTag *min(const String &val);
HTMLTag *step(const String &val);
HTMLTag *step_any();
HTMLTag *minlength(const int val);
HTMLTag *minlength(const String &val);
HTMLTag *maxlength(const int val);
HTMLTag *maxlength(const String &val);
HTMLTag *size(const int val);
HTMLTag *size(const String &val);
HTMLTag *width(const int val);
HTMLTag *width(const String &val);
HTMLTag *height(const int val);
HTMLTag *height(const String &val);
HTMLTag *method(const String &val); HTMLTag *method(const String &val);
HTMLTag *action(const String &val); HTMLTag *action(const String &val);
HTMLTag *type(const String &val); HTMLTag *type(const String &val);
@ -53,6 +82,15 @@ public:
HTMLTag *iturl(); HTMLTag *iturl();
HTMLTag *itweek(); HTMLTag *itweek();
HTMLTag *inputmode_none();
HTMLTag *inputmode_text();
HTMLTag *inputmode_decimal();
HTMLTag *inputmode_numeric();
HTMLTag *inputmode_tel();
HTMLTag *inputmode_search();
HTMLTag *inputmode_email();
HTMLTag *inputmode_url();
HTMLTag *attrib(const String &attr, const String &val); HTMLTag *attrib(const String &attr, const String &val);
HTMLTag *start(const String &p_new_tag, const bool p_simple = false); HTMLTag *start(const String &p_new_tag, const bool p_simple = false);
@ -355,6 +393,35 @@ public:
HTMLTag *input_url(); HTMLTag *input_url();
HTMLTag *input_week(); HTMLTag *input_week();
//label!
//autocomplete
//onclick, etc
HTMLTag *input_button(const String& name, const String& value = "", const String& cls = "", const String& id = "");
HTMLTag *input_checkbox(const String& name, const String& value = "", const String& cls = "", const String& id = "");
HTMLTag *input_color(const String& name, const String& value = "", const String& cls = "", const String& id = "");
HTMLTag *input_date(const String& name, const String& value = "", const String& cls = "", const String& id = "", const String& date_min = "", const String& date_max = "", const String& date_step = "");
HTMLTag *input_datetime_local(const String& name, const String& value = "", const String& cls = "", const String& id = "", const String& date_min = "", const String& date_max = "", const String& date_step = "");
HTMLTag *input_email(const String& name, const String& value = "", const String& placeholder = "", const String& cls = "", const String& id = "");
HTMLTag *input_file(const String& name, const String& accept = "", const String& cls = "", const String& id = "");
HTMLTag *input_image(const String& name, const String& src = "", const String& alt = "", const String& cls = "", const String& id = "", const int width = 0, const int height = 0);
HTMLTag *input_month(const String& name, const String& cls = "", const String& id = "");
HTMLTag *input_number(const String& name, const String& = "", const String& = "", const String& cls = "", const String& id = "");
HTMLTag *input_password(const String& name, const String& value = "", const String& placeholder = "", const String& cls = "", const String& id = "", const String& minlength = "", const String& maxlength = "", const String& size = "");
HTMLTag *input_radio(const String& name, const String& value = "", const String& cls = "", const String& id = "");
HTMLTag *input_range(const String& name, const String& value = "", const String& vmin = "", const String& vmax = "", const String& vstep = "", const String& cls = "", const String& id = "");
HTMLTag *input_reset(const String& name, const String& value = "", const String& cls = "", const String& id = "");
/*
HTMLTag *input_search();
HTMLTag *input_submit();
HTMLTag *input_tel();
HTMLTag *input_text();
HTMLTag *input_time();
HTMLTag *input_url();
HTMLTag *input_week();
*/
void f(); void f();
//write //write