Fixes to form handling
authorMyhailo Danylenko <isbear@ukrpost.net>
Sun, 22 Mar 2009 19:46:26 +0200
changeset 53 2162188b20cf
parent 52 50d4e9bc622d
child 54 b53355736057
Fixes to form handling
TODO
examples/iq_register.lua
examples/pubsub.lua
examples/x_data.lua
--- a/TODO	Sun Mar 22 18:15:58 2009 +0200
+++ b/TODO	Sun Mar 22 19:46:26 2009 +0200
@@ -19,4 +19,5 @@
 common disco routines should get connection object from outer space - no mcabber dependency, the same for forms parsing, pep sending (though it anyway needs to be converted to pubsub)...
 tune should set self-song only on reply from server
 test node config
+publish library handlers?
 
--- a/examples/iq_register.lua	Sun Mar 22 18:15:58 2009 +0200
+++ b/examples/iq_register.lua	Sun Mar 22 19:46:26 2009 +0200
@@ -1,8 +1,6 @@
 
 -- IN-BAND REGISTRATION (XEP-0077)
 
--- FIXME this is not yet finished, as format of form is undecided yet
-
 -- library
 
 require 'lm'
@@ -27,13 +25,13 @@
 	end
 
 	local x = query:child ( 'x' )
-	if x:attribute ( 'xmlns' ) == 'jabber:x:data' then
-		form = form.parse ( x )
+	if x and x:attribute ( 'xmlns' ) == 'jabber:x:data' then
+		form = x_data.parse ( x )
 		local format = form.format
 		form.format =
 			function ( form, root )
-					root.query = format ( form, { xmlns = 'jabber:iq:register' } )
-					return root
+				root.query = format ( form, { xmlns = 'jabber:iq:register' } )
+				return root
 			end
 		return form
 	end
@@ -42,7 +40,7 @@
 	while field do
 		local name  = field:name ()
 		if name ~= 'instructions' and name ~= 'registered' then
-			table.insert ( form, { type = 'text-single', var = name, value = { field:value () or '' } } )
+			table.insert ( form, { type = 'text-single', var = name, value = field:value () or '' } )
 		end
 		field = field:next ()
 	end
--- a/examples/pubsub.lua	Sun Mar 22 18:15:58 2009 +0200
+++ b/examples/pubsub.lua	Sun Mar 22 19:46:26 2009 +0200
@@ -129,6 +129,7 @@
 			if x then
 				success ( x_data.parse ( x ),
 					function ( form, success, fail )
+						form.type = 'submit'
 						iq.send ( conn, to, 'set',
 							{
 								pubsub = { xmlns = 'http://jabber.org/protocol/pubsub#owner',
--- a/examples/x_data.lua	Sun Mar 22 18:15:58 2009 +0200
+++ b/examples/x_data.lua	Sun Mar 22 19:46:26 2009 +0200
@@ -183,7 +183,7 @@
 								fields = fields .. '\n    * ' .. value
 							end
 						else
-							fields = fields .. '\n   Value: ' .. field.value
+							fields = fields .. '\n   Value: ' .. ( field.value or '' )
 						end
 					else
 						if type(field) ~= 'function' then -- skip any methods