[Lift] Re: JSON form with

2009-07-31 Thread James Kearney

I have had a look at the change, while better than the old one it
still causes problems if you use a  in a text box because you are
building JSON as a string and then parsing it.

In my example code you go from a javascript object to another one
there is no need for parsing so you don't run into problems with
escape characters.

I don't know if you are building the JSON as a string then parsing it
for compatibility reasons if so you should escape any  found in the
name and value.
e.g.
json += \ + e.name.replace(/\/g,\\\) + \:\ + e.value.replace
(/\/g,\\\) + \,;


James

On Jul 30, 6:14 pm, marius d. marius.dan...@gmail.com wrote:
 James,

 I just committed the fix based on your approach. Please give it a try.

 Br's,
 Marius

 On Jul 30, 4:53 pm, marius d. marius.dan...@gmail.com wrote:

  Thank you James for your input. I hope I'll be able to look into it
  today.

  Br's,
  Marius

  On Jul 30, 4:42 pm, James Kearney ghostf...@googlemail.com wrote:

   I think the current implementation of the JSON form is broken.

   If you put an  in a text field and try to submit it via a JSON form
   it doesn't get handled correctly.

   To be precise the formToJSON function in jlift.js doesn't work, and
   again to be more precise the params method is broken / not fit for
   purpose.

   The params method (line 249) calls s.join() and then returns but it
   doesn't escape the  character (it also uses = but doesn't escape
   that). If the params function does what I think it is supposed to do
   which is split paramters for a URL then it should really call
   encodeURI on the values.

   That aside I don't think the formToJSON function should be using the
   param function. It gets a JSON object from jQuery serializeArray makes
   it into a string split by  and = then goes and splits based on  and
   = again building up some JSON (as a string) then parses the JSON. Why
   not operate on the JSON from jQuery from the start.
   e.g.

   formToJSON : function(formId)
              {
                  json = jQuery(# + formId).serializeArray();
                  ret = {}

                  for (var i in json)
                  {
                      var obj = json[i]

                      ret[obj.name] = obj.value
                  }

                  return ret;
              }

   This does work differently from before since it won't call functions
   like params does but I don't think jQuery's serializeArray puts
   functions in the object it returns so that is not needed.

   James

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: JSON form with

2009-07-31 Thread David Pollak
I'm curious as to why we have this function floating around in the first
place.  Isn't this something best done by a JavaScript library that has been
tested cross browser (e.g., something in jQuery or YUI)?
Also, doesn't the param function hardcode a dependency on jQuery... and
we're support to be agnostic about the JavaScript library that we sit on?

On Fri, Jul 31, 2009 at 3:34 AM, James Kearney ghostf...@googlemail.comwrote:


 I have had a look at the change, while better than the old one it
 still causes problems if you use a  in a text box because you are
 building JSON as a string and then parsing it.

 In my example code you go from a javascript object to another one
 there is no need for parsing so you don't run into problems with
 escape characters.

 I don't know if you are building the JSON as a string then parsing it
 for compatibility reasons if so you should escape any  found in the
 name and value.
 e.g.
 json += \ + e.name.replace(/\/g,\\\) + \:\ + e.value.replace
 (/\/g,\\\) + \,;


 James

 On Jul 30, 6:14 pm, marius d. marius.dan...@gmail.com wrote:
  James,
 
  I just committed the fix based on your approach. Please give it a try.
 
  Br's,
  Marius
 
  On Jul 30, 4:53 pm, marius d. marius.dan...@gmail.com wrote:
 
   Thank you James for your input. I hope I'll be able to look into it
   today.
 
   Br's,
   Marius
 
   On Jul 30, 4:42 pm, James Kearney ghostf...@googlemail.com wrote:
 
I think the current implementation of the JSON form is broken.
 
If you put an  in a text field and try to submit it via a JSON form
it doesn't get handled correctly.
 
To be precise the formToJSON function in jlift.js doesn't work, and
again to be more precise the params method is broken / not fit for
purpose.
 
The params method (line 249) calls s.join() and then returns but
 it
doesn't escape the  character (it also uses = but doesn't escape
that). If the params function does what I think it is supposed to do
which is split paramters for a URL then it should really call
encodeURI on the values.
 
That aside I don't think the formToJSON function should be using the
param function. It gets a JSON object from jQuery serializeArray
 makes
it into a string split by  and = then goes and splits based on  and
= again building up some JSON (as a string) then parses the JSON. Why
not operate on the JSON from jQuery from the start.
e.g.
 
formToJSON : function(formId)
   {
   json = jQuery(# + formId).serializeArray();
   ret = {}
 
   for (var i in json)
   {
   var obj = json[i]
 
   ret[obj.name] = obj.value
   }
 
   return ret;
   }
 
This does work differently from before since it won't call functions
like params does but I don't think jQuery's serializeArray puts
functions in the object it returns so that is not needed.
 
James

 



-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: JSON form with

2009-07-31 Thread marius d.



On Jul 31, 4:42 pm, David Pollak feeder.of.the.be...@gmail.com
wrote:
 I'm curious as to why we have this function floating around in the first
 place.  Isn't this something best done by a JavaScript library that has been
 tested cross browser (e.g., something in jQuery or YUI)?
 Also, doesn't the param function hardcode a dependency on jQuery... and
 we're support to be agnostic about the JavaScript library that we sit on?

I don't think that it was dependent on JQuery. Anyways that is gone
now.


 On Fri, Jul 31, 2009 at 3:34 AM, James Kearney 
 ghostf...@googlemail.comwrote:





  I have had a look at the change, while better than the old one it
  still causes problems if you use a  in a text box because you are
  building JSON as a string and then parsing it.

  In my example code you go from a javascript object to another one
  there is no need for parsing so you don't run into problems with
  escape characters.

  I don't know if you are building the JSON as a string then parsing it
  for compatibility reasons if so you should escape any  found in the
  name and value.
  e.g.
  json += \ + e.name.replace(/\/g,\\\) + \:\ + e.value.replace
  (/\/g,\\\) + \,;

  James

  On Jul 30, 6:14 pm, marius d. marius.dan...@gmail.com wrote:
   James,

   I just committed the fix based on your approach. Please give it a try.

   Br's,
   Marius

   On Jul 30, 4:53 pm, marius d. marius.dan...@gmail.com wrote:

Thank you James for your input. I hope I'll be able to look into it
today.

Br's,
Marius

On Jul 30, 4:42 pm, James Kearney ghostf...@googlemail.com wrote:

 I think the current implementation of the JSON form is broken.

 If you put an  in a text field and try to submit it via a JSON form
 it doesn't get handled correctly.

 To be precise the formToJSON function in jlift.js doesn't work, and
 again to be more precise the params method is broken / not fit for
 purpose.

 The params method (line 249) calls s.join() and then returns but
  it
 doesn't escape the  character (it also uses = but doesn't escape
 that). If the params function does what I think it is supposed to do
 which is split paramters for a URL then it should really call
 encodeURI on the values.

 That aside I don't think the formToJSON function should be using the
 param function. It gets a JSON object from jQuery serializeArray
  makes
 it into a string split by  and = then goes and splits based on  and
 = again building up some JSON (as a string) then parses the JSON. Why
 not operate on the JSON from jQuery from the start.
 e.g.

 formToJSON : function(formId)
            {
                json = jQuery(# + formId).serializeArray();
                ret = {}

                for (var i in json)
                {
                    var obj = json[i]

                    ret[obj.name] = obj.value
                }

                return ret;
            }

 This does work differently from before since it won't call functions
 like params does but I don't think jQuery's serializeArray puts
 functions in the object it returns so that is not needed.

 James

 --
 Lift, the simply functional web frameworkhttp://liftweb.net
 Beginning Scalahttp://www.apress.com/book/view/1430219890
 Follow me:http://twitter.com/dpp
 Git some:http://github.com/dpp
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: JSON form with

2009-07-31 Thread marius d.

James,

I just tested jsonForm with #$%^*(){}[]:;'|\,.?/|\ characters and
الصفحة الر for testing international chars. Everything worked
correctly. I am using FF3 on Ubuntu.

What problems did you run into?

P.S.
What I committed yesterday is exactly your code so I don't get what
the problem is. Did you do a git pull on master ?

Br's,
Marius

On Jul 31, 1:34 pm, James Kearney ghostf...@googlemail.com wrote:
 I have had a look at the change, while better than the old one it
 still causes problems if you use a  in a text box because you are
 building JSON as a string and then parsing it.

 In my example code you go from a javascript object to another one
 there is no need for parsing so you don't run into problems with
 escape characters.

 I don't know if you are building the JSON as a string then parsing it
 for compatibility reasons if so you should escape any  found in the
 name and value.
 e.g.
 json += \ + e.name.replace(/\/g,\\\) + \:\ + e.value.replace
 (/\/g,\\\) + \,;

 James

 On Jul 30, 6:14 pm, marius d. marius.dan...@gmail.com wrote:

  James,

  I just committed the fix based on your approach. Please give it a try.

  Br's,
  Marius

  On Jul 30, 4:53 pm, marius d. marius.dan...@gmail.com wrote:

   Thank you James for your input. I hope I'll be able to look into it
   today.

   Br's,
   Marius

   On Jul 30, 4:42 pm, James Kearney ghostf...@googlemail.com wrote:

I think the current implementation of the JSON form is broken.

If you put an  in a text field and try to submit it via a JSON form
it doesn't get handled correctly.

To be precise the formToJSON function in jlift.js doesn't work, and
again to be more precise the params method is broken / not fit for
purpose.

The params method (line 249) calls s.join() and then returns but it
doesn't escape the  character (it also uses = but doesn't escape
that). If the params function does what I think it is supposed to do
which is split paramters for a URL then it should really call
encodeURI on the values.

That aside I don't think the formToJSON function should be using the
param function. It gets a JSON object from jQuery serializeArray makes
it into a string split by  and = then goes and splits based on  and
= again building up some JSON (as a string) then parses the JSON. Why
not operate on the JSON from jQuery from the start.
e.g.

formToJSON : function(formId)
           {
               json = jQuery(# + formId).serializeArray();
               ret = {}

               for (var i in json)
               {
                   var obj = json[i]

                   ret[obj.name] = obj.value
               }

               return ret;
           }

This does work differently from before since it won't call functions
like params does but I don't think jQuery's serializeArray puts
functions in the object it returns so that is not needed.

James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: JSON form with

2009-07-31 Thread James Kearney

Ah, sorry my mistake I was looking at the first of the two commits you
made

On Jul 31, 4:52 pm, marius d. marius.dan...@gmail.com wrote:
 James,

 I just tested jsonForm with #$%^*(){}[]:;'|\,.?/|\ characters and
 الصفحة الر for testing international chars. Everything worked
 correctly. I am using FF3 on Ubuntu.

 What problems did you run into?

 P.S.
 What I committed yesterday is exactly your code so I don't get what
 the problem is. Did you do a git pull on master ?

 Br's,
 Marius

 On Jul 31, 1:34 pm, James Kearney ghostf...@googlemail.com wrote:

  I have had a look at the change, while better than the old one it
  still causes problems if you use a  in a text box because you are
  building JSON as a string and then parsing it.

  In my example code you go from a javascript object to another one
  there is no need for parsing so you don't run into problems with
  escape characters.

  I don't know if you are building the JSON as a string then parsing it
  for compatibility reasons if so you should escape any  found in the
  name and value.
  e.g.
  json += \ + e.name.replace(/\/g,\\\) + \:\ + e.value.replace
  (/\/g,\\\) + \,;

  James

  On Jul 30, 6:14 pm, marius d. marius.dan...@gmail.com wrote:

   James,

   I just committed the fix based on your approach. Please give it a try.

   Br's,
   Marius

   On Jul 30, 4:53 pm, marius d. marius.dan...@gmail.com wrote:

Thank you James for your input. I hope I'll be able to look into it
today.

Br's,
Marius

On Jul 30, 4:42 pm, James Kearney ghostf...@googlemail.com wrote:

 I think the current implementation of the JSON form is broken.

 If you put an  in a text field and try to submit it via a JSON form
 it doesn't get handled correctly.

 To be precise the formToJSON function in jlift.js doesn't work, and
 again to be more precise the params method is broken / not fit for
 purpose.

 The params method (line 249) calls s.join() and then returns but it
 doesn't escape the  character (it also uses = but doesn't escape
 that). If the params function does what I think it is supposed to do
 which is split paramters for a URL then it should really call
 encodeURI on the values.

 That aside I don't think the formToJSON function should be using the
 param function. It gets a JSON object from jQuery serializeArray makes
 it into a string split by  and = then goes and splits based on  and
 = again building up some JSON (as a string) then parses the JSON. Why
 not operate on the JSON from jQuery from the start.
 e.g.

 formToJSON : function(formId)
            {
                json = jQuery(# + formId).serializeArray();
                ret = {}

                for (var i in json)
                {
                    var obj = json[i]

                    ret[obj.name] = obj.value
                }

                return ret;
            }

 This does work differently from before since it won't call functions
 like params does but I don't think jQuery's serializeArray puts
 functions in the object it returns so that is not needed.

 James

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: JSON form with

2009-07-30 Thread marius d.

Thank you James for your input. I hope I'll be able to look into it
today.

Br's,
Marius

On Jul 30, 4:42 pm, James Kearney ghostf...@googlemail.com wrote:
 I think the current implementation of the JSON form is broken.

 If you put an  in a text field and try to submit it via a JSON form
 it doesn't get handled correctly.

 To be precise the formToJSON function in jlift.js doesn't work, and
 again to be more precise the params method is broken / not fit for
 purpose.

 The params method (line 249) calls s.join() and then returns but it
 doesn't escape the  character (it also uses = but doesn't escape
 that). If the params function does what I think it is supposed to do
 which is split paramters for a URL then it should really call
 encodeURI on the values.

 That aside I don't think the formToJSON function should be using the
 param function. It gets a JSON object from jQuery serializeArray makes
 it into a string split by  and = then goes and splits based on  and
 = again building up some JSON (as a string) then parses the JSON. Why
 not operate on the JSON from jQuery from the start.
 e.g.

 formToJSON : function(formId)
            {
                json = jQuery(# + formId).serializeArray();
                ret = {}

                for (var i in json)
                {
                    var obj = json[i]

                    ret[obj.name] = obj.value
                }

                return ret;
            }

 This does work differently from before since it won't call functions
 like params does but I don't think jQuery's serializeArray puts
 functions in the object it returns so that is not needed.

 James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: JSON form with

2009-07-30 Thread marius d.

James,

I just committed the fix based on your approach. Please give it a try.

Br's,
Marius

On Jul 30, 4:53 pm, marius d. marius.dan...@gmail.com wrote:
 Thank you James for your input. I hope I'll be able to look into it
 today.

 Br's,
 Marius

 On Jul 30, 4:42 pm, James Kearney ghostf...@googlemail.com wrote:

  I think the current implementation of the JSON form is broken.

  If you put an  in a text field and try to submit it via a JSON form
  it doesn't get handled correctly.

  To be precise the formToJSON function in jlift.js doesn't work, and
  again to be more precise the params method is broken / not fit for
  purpose.

  The params method (line 249) calls s.join() and then returns but it
  doesn't escape the  character (it also uses = but doesn't escape
  that). If the params function does what I think it is supposed to do
  which is split paramters for a URL then it should really call
  encodeURI on the values.

  That aside I don't think the formToJSON function should be using the
  param function. It gets a JSON object from jQuery serializeArray makes
  it into a string split by  and = then goes and splits based on  and
  = again building up some JSON (as a string) then parses the JSON. Why
  not operate on the JSON from jQuery from the start.
  e.g.

  formToJSON : function(formId)
             {
                 json = jQuery(# + formId).serializeArray();
                 ret = {}

                 for (var i in json)
                 {
                     var obj = json[i]

                     ret[obj.name] = obj.value
                 }

                 return ret;
             }

  This does work differently from before since it won't call functions
  like params does but I don't think jQuery's serializeArray puts
  functions in the object it returns so that is not needed.

  James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: json form

2008-09-01 Thread Marius

I also copy pasted your code and it compiles and works fine for me.
But if you're using Scala 2.7.2 it might cause problems. Can you try
with 2.7.1?

Br's,
Marius

On Sep 1, 8:04 pm, Marius [EMAIL PROTECTED] wrote:
 Hi,

 I have pretty much the same code working just fine but the imports are
 slightly different

 package lifttest.snippet

 import scala.xml._
 import net.liftweb.http._
 import net.liftweb.http.S._
 import net.liftweb.http.SHtml._
 import net.liftweb.http.{RequestVar}
 import net.liftweb.util.Helpers._
 import net.liftweb.util._
 import net.liftweb.util.Can._
 import net.liftweb.http.js._
 // import net.liftweb.http.js.jquery.JqJsCmds._
 import JsCmds._

 class JSONForm {

   def show(html: Group): NodeSeq = {
 jsonForm(json, html)
   }

   object json extends JsonHandler {
 def apply(in: Any): JsCmd =
   SetHtml(json_result, in match {
 case [EMAIL PROTECTED](processForm, _, p: Map[String, _], _) = {
   println(Cars =  + p(cars))
   println(Name =  + p(name))
   b{p}/b
 }
 case x = bProblem... didn't handle JSON message {x}/b
   })
   }

   def head = head{Script(json.jsCmd)}/head

 }

 Also are you packages set up correctly? What Scala version are you
 using? Can you try mvn clean first ?

 Br's,
 Marius

 On Sep 1, 6:23 pm, Acciaio [EMAIL PROTECTED] wrote:

  import scala.xml._
  import net.liftweb.http._
  import net.liftweb.http.S._
  import net.liftweb.http.SHtml._
  import net.liftweb.http.{RequestVar}
  import net.liftweb.util.Helpers._
  import net.liftweb.util._
  import net.liftweb.util.Can._
  import net.liftweb.http.js._

  class JSONForm {

def show(html: Group): NodeSeq = {
  jsonForm(json, html)  //Both way in this form or in the
  complete one posted before...
}

import JsCmds._
object json extends JsonHandler {
  def apply(in: Any): JsCmd =
SetHtml(json_result, in match {
  case [EMAIL PROTECTED](processForm, _, p: Map[String, _], _) = {
println(Cars =  + p(cars))
b{p}/b
  }
  case x = bProblem... didn't handle JSON message {x}/b
})
}

def head = head{Script(json.jsCmd)}/head
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---