Add maxlength attribute to input and textarea tags

This commit is contained in:
Nimetu 2014-09-27 15:55:57 +03:00
parent 1291837873
commit 4a5a2e1a2f
4 changed files with 21 additions and 11 deletions

View file

@ -285,7 +285,7 @@ namespace NLGUI
void addImage(const char *image, bool globalColor, bool reloadImg=false); void addImage(const char *image, bool globalColor, bool reloadImg=false);
// Add a text area in the current paragraph // Add a text area in the current paragraph
CInterfaceGroup *addTextArea (const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const ucstring &content); CInterfaceGroup *addTextArea (const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const ucstring &content, uint maxlength);
// Add a combo box in the current paragraph // Add a combo box in the current paragraph
CDBGroupComboBox *addComboBox(const std::string &templateName, const char *name); CDBGroupComboBox *addComboBox(const std::string &templateName, const char *name);
@ -557,6 +557,7 @@ namespace NLGUI
std::string _TextAreaName; std::string _TextAreaName;
uint _TextAreaRow; uint _TextAreaRow;
uint _TextAreaCols; uint _TextAreaCols;
uint _TextAreaMaxLength;
// current mode is in select option // current mode is in select option
bool _SelectOption; bool _SelectOption;

View file

@ -189,6 +189,7 @@ namespace NLGUI
HTML_ATTR(TEXTAREA,DISABLED), HTML_ATTR(TEXTAREA,DISABLED),
HTML_ATTR(TEXTAREA,ID), HTML_ATTR(TEXTAREA,ID),
HTML_ATTR(TEXTAREA,LANG), HTML_ATTR(TEXTAREA,LANG),
HTML_ATTR(TEXTAREA,MAXLENGTH),
HTML_ATTR(TEXTAREA,NAME), HTML_ATTR(TEXTAREA,NAME),
HTML_ATTR(TEXTAREA,READONLY), HTML_ATTR(TEXTAREA,READONLY),
HTML_ATTR(TEXTAREA,ROWS), HTML_ATTR(TEXTAREA,ROWS),

View file

@ -1289,16 +1289,19 @@ namespace NLGUI
string name; string name;
ucstring ucValue; ucstring ucValue;
uint size = 120; uint size = 120;
uint maxlength = 1024;
if (present[MY_HTML_INPUT_NAME] && value[MY_HTML_INPUT_NAME]) if (present[MY_HTML_INPUT_NAME] && value[MY_HTML_INPUT_NAME])
name = value[MY_HTML_INPUT_NAME]; name = value[MY_HTML_INPUT_NAME];
if (present[MY_HTML_INPUT_SIZE] && value[MY_HTML_INPUT_SIZE]) if (present[MY_HTML_INPUT_SIZE] && value[MY_HTML_INPUT_SIZE])
fromString(value[MY_HTML_INPUT_SIZE], size); fromString(value[MY_HTML_INPUT_SIZE], size);
if (present[MY_HTML_INPUT_VALUE] && value[MY_HTML_INPUT_VALUE]) if (present[MY_HTML_INPUT_VALUE] && value[MY_HTML_INPUT_VALUE])
ucValue.fromUtf8(value[MY_HTML_INPUT_VALUE]); ucValue.fromUtf8(value[MY_HTML_INPUT_VALUE]);
if (present[MY_HTML_INPUT_MAXLENGTH] && value[MY_HTML_INPUT_MAXLENGTH])
fromString(value[MY_HTML_INPUT_MAXLENGTH], maxlength);
string textTemplate(!templateName.empty() ? templateName : DefaultFormTextGroup); string textTemplate(!templateName.empty() ? templateName : DefaultFormTextGroup);
// Add the editbox // Add the editbox
CInterfaceGroup *textArea = addTextArea (textTemplate, name.c_str (), 1, size/12, false, ucValue); CInterfaceGroup *textArea = addTextArea (textTemplate, name.c_str (), 1, size/12, false, ucValue, maxlength);
if (textArea) if (textArea)
{ {
// Add the text area to the form // Add the text area to the form
@ -1553,12 +1556,15 @@ namespace NLGUI
_TextAreaRow = 1; _TextAreaRow = 1;
_TextAreaCols = 10; _TextAreaCols = 10;
_TextAreaContent = ""; _TextAreaContent = "";
if (present[HTML_TEXTAREA_NAME] && value[HTML_TEXTAREA_NAME]) _TextAreaMaxLength = 1024;
_TextAreaName = value[HTML_TEXTAREA_NAME]; if (present[MY_HTML_TEXTAREA_NAME] && value[MY_HTML_TEXTAREA_NAME])
if (present[HTML_TEXTAREA_ROWS] && value[HTML_TEXTAREA_ROWS]) _TextAreaName = value[MY_HTML_TEXTAREA_NAME];
fromString(value[HTML_TEXTAREA_ROWS], _TextAreaRow); if (present[MY_HTML_TEXTAREA_ROWS] && value[MY_HTML_TEXTAREA_ROWS])
if (present[HTML_TEXTAREA_COLS] && value[HTML_TEXTAREA_COLS]) fromString(value[MY_HTML_TEXTAREA_ROWS], _TextAreaRow);
fromString(value[HTML_TEXTAREA_COLS], _TextAreaCols); if (present[MY_HTML_TEXTAREA_COLS] && value[MY_HTML_TEXTAREA_COLS])
fromString(value[MY_HTML_TEXTAREA_COLS], _TextAreaCols);
if (present[MY_HTML_TEXTAREA_MAXLENGTH] && value[MY_HTML_TEXTAREA_MAXLENGTH])
fromString(value[MY_HTML_TEXTAREA_MAXLENGTH], _TextAreaMaxLength);
_TextAreaTemplate = !templateName.empty() ? templateName : DefaultFormTextAreaGroup; _TextAreaTemplate = !templateName.empty() ? templateName : DefaultFormTextAreaGroup;
_TextArea = true; _TextArea = true;
@ -1680,7 +1686,7 @@ namespace NLGUI
// nlinfo("textarea name '%s'", _TextAreaName.c_str()); // nlinfo("textarea name '%s'", _TextAreaName.c_str());
// nlinfo("textarea %d %d", _TextAreaRow, _TextAreaCols); // nlinfo("textarea %d %d", _TextAreaRow, _TextAreaCols);
// nlinfo("textarea content '%s'", _TextAreaContent.toUtf8().c_str()); // nlinfo("textarea content '%s'", _TextAreaContent.toUtf8().c_str());
CInterfaceGroup *textArea = addTextArea (_TextAreaTemplate, _TextAreaName.c_str (), _TextAreaRow, _TextAreaCols, true, _TextAreaContent); CInterfaceGroup *textArea = addTextArea (_TextAreaTemplate, _TextAreaName.c_str (), _TextAreaRow, _TextAreaCols, true, _TextAreaContent, _TextAreaMaxLength);
if (textArea) if (textArea)
{ {
// Add the text area to the form // Add the text area to the form
@ -3258,7 +3264,7 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
CInterfaceGroup *CGroupHTML::addTextArea(const std::string &templateName, const char *name, uint /* rows */, uint cols, bool multiLine, const ucstring &content) CInterfaceGroup *CGroupHTML::addTextArea(const std::string &templateName, const char *name, uint /* rows */, uint cols, bool multiLine, const ucstring &content, uint maxlength)
{ {
// In a paragraph ? // In a paragraph ?
if (!_Paragraph) if (!_Paragraph)
@ -3280,7 +3286,8 @@ namespace NLGUI
templateParams.push_back (std::pair<std::string,std::string> ("multiline", multiLine?"true":"false")); templateParams.push_back (std::pair<std::string,std::string> ("multiline", multiLine?"true":"false"));
templateParams.push_back (std::pair<std::string,std::string> ("want_return", multiLine?"true":"false")); templateParams.push_back (std::pair<std::string,std::string> ("want_return", multiLine?"true":"false"));
templateParams.push_back (std::pair<std::string,std::string> ("enter_recover_focus", "false")); templateParams.push_back (std::pair<std::string,std::string> ("enter_recover_focus", "false"));
templateParams.push_back (std::pair<std::string,std::string> ("max_num_chars", "1024")); if (maxlength > 0)
templateParams.push_back (std::pair<std::string,std::string> ("max_num_chars", toString(maxlength)));
CInterfaceGroup *textArea = CWidgetManager::getInstance()->getParser()->createGroupInstance (templateName.c_str(), CInterfaceGroup *textArea = CWidgetManager::getInstance()->getParser()->createGroupInstance (templateName.c_str(),
getParagraph()->getId(), templateParams.empty()?NULL:&(templateParams[0]), (uint)templateParams.size()); getParagraph()->getId(), templateParams.empty()?NULL:&(templateParams[0]), (uint)templateParams.size());

View file

@ -201,6 +201,7 @@ namespace NLGUI
HTML_ATTR(TEXTAREA,DISABLED), HTML_ATTR(TEXTAREA,DISABLED),
HTML_ATTR(TEXTAREA,ID), HTML_ATTR(TEXTAREA,ID),
HTML_ATTR(TEXTAREA,LANG), HTML_ATTR(TEXTAREA,LANG),
HTML_ATTR(TEXTAREA,MAXLENGTH),
HTML_ATTR(TEXTAREA,NAME), HTML_ATTR(TEXTAREA,NAME),
HTML_ATTR(TEXTAREA,READONLY), HTML_ATTR(TEXTAREA,READONLY),
HTML_ATTR(TEXTAREA,ROWS), HTML_ATTR(TEXTAREA,ROWS),