summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Sluift/ElementConvertors/FormConvertor.cpp12
-rw-r--r--Sluift/Tests/FormTest.lua17
2 files changed, 20 insertions, 9 deletions
diff --git a/Sluift/ElementConvertors/FormConvertor.cpp b/Sluift/ElementConvertors/FormConvertor.cpp
index 9791bfa..26a7d29 100644
--- a/Sluift/ElementConvertors/FormConvertor.cpp
+++ b/Sluift/ElementConvertors/FormConvertor.cpp
@@ -90,17 +90,15 @@ namespace {
if (!field->getDescription().empty()) {
luaField["description"] = Lua::valueRef(field->getDescription());
}
-
- if (field->getType() == FormField::ListMultiType || field->getType() == FormField::JIDMultiType || field->getType() == FormField::TextMultiType) {
- luaField["value"] = Lua::valueRef(Lua::Array(field->getValues().begin(), field->getValues().end()));
- }
- else if (field->getType() == FormField::BooleanType) {
+ if (field->getType() == FormField::BooleanType) {
luaField["value"] = Lua::boolRef(field->getBoolValue());
}
- else if (!field->getValues().empty()) {
+ else if (field->getValues().size() > 1) {
+ luaField["value"] = Lua::valueRef(Lua::Array(field->getValues().begin(), field->getValues().end()));
+ }
+ else if (field->getValues().size() == 1) {
luaField["value"] = Lua::valueRef(field->getValues()[0]);
}
-
if (!field->getOptions().empty()) {
Lua::Array options;
foreach(const FormField::Option& option, field->getOptions()) {
diff --git a/Sluift/Tests/FormTest.lua b/Sluift/Tests/FormTest.lua
index b2ec111..3b311da 100644
--- a/Sluift/Tests/FormTest.lua
+++ b/Sluift/Tests/FormTest.lua
@@ -13,7 +13,10 @@ example_form = [[
</field>
<field type='fixed'><value>Section 1: Bot Info</value></field>
<field type='text-single' label='The name of your bot' var='botname'/>
- <field type='text-multi' label='Helpful description of your bot' var='description'/>
+ <field type='text-multi' label='Helpful description of your bot' var='description'>
+ <value>This is</value>
+ <value>my bot</value>
+ </field>
<field type='boolean' label='Public bot?' var='public'>
<required/>
</field>
@@ -71,9 +74,19 @@ assert(form['FORM_TYPE']['value'] == 'jabber:bot')
-- Test response form
submission = form:create_submission()
assert(#(submission.fields) == 8)
+description_submit_value = submission['description']['value']
+assert(type(description_submit_value) == 'table')
+assert(description_submit_value[1] == 'This is')
+assert(description_submit_value[2] == 'my bot')
+
submission['description'] = 'my description'
assert(submission['description']['value'] == 'my description')
submission['type'] = 'cancel'
-assert(#(submission.fields) == 8)
+
+-- Test text-multi field
+text_multi_field = form['fields'][4]
+assert(text_multi_field['name'] == 'description')
+assert(type(text_multi_field['value']) == 'table')
+
--print(sluift.to_xml({type = 'form', data = form}))