diff options
author | Remko Tronçon <git@el-tramo.be> | 2013-12-15 11:30:03 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2013-12-23 13:26:55 (GMT) |
commit | 2cb6df163319cdef371607ad527558e09d707129 (patch) | |
tree | 0947c5b5acf7010ff52a37a41a612777d42924c5 | |
parent | 26994474c1ebfe874c2cd62ededf9a82b0496136 (diff) | |
download | swift-2cb6df163319cdef371607ad527558e09d707129.zip swift-2cb6df163319cdef371607ad527558e09d707129.tar.bz2 |
Sluift: Fix create_submission dropping values from multi fields
Form->Lua conversion no longer relies on the type to decide how to
convert values, and blindly converts value arrays.
This also fixes issues if Sluift would be used on the receiving
side of a form.
Change-Id: I92c346795e1c67c74ccf542d16f79fe8010508f7
-rw-r--r-- | Sluift/ElementConvertors/FormConvertor.cpp | 12 | ||||
-rw-r--r-- | Sluift/Tests/FormTest.lua | 17 |
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})) |