FreedomCoop / valuenetwork

Fork coming from NRP-Sensorica to use and work for FREEDOM COOP
http://fair.coop
GNU Affero General Public License v3.0
31 stars 12 forks source link

Bug at recovering form data on reload in joinaproject #148

Closed bum2 closed 8 years ago

bum2 commented 8 years ago

There's a bug in the js trick to fill-up the custom form fields when reload or error (in public project forms): if you type a line-break in the field text the js crashes. Is needed more parsing to convert line-breaks to safe js string before sending var 'post' to the template from view.py def joinaproject_request to the joinaproject_request.html template

bhaugen commented 8 years ago

How to reproduce this locally?

bum2 commented 8 years ago

do just that (place a text with line-breaks in a custom field of a public join-request form) and check how the JS fails when trying to fill again the screen field data with the POST values, when reload or any error in the form or captcha. Because the js breaks, the order of the form fields is bad again also (with the captcha in the middle of the form, and the presentation custom text below it) beacuse that fields are ordered via jquery.

bhaugen commented 8 years ago

Reproduced. Thinking about it...

[Edit] Console says:

VM1926:1 Uncaught SyntaxError: Unexpected token 
(anonymous function) @ (index):50

Error display:

{"phone_number": "", "requested_username": "", "submit": "Submit", "surname": "", "name": "", "aparticipatingfaircoopecosystemfaircoin": "no

not yet", "proveonlinepresencerelatedyourprofile": "", "captcha_1": "", "experiencewithsameprinciplesasfaircoop": "", "captcha_0": "a87b65dd95c78e878472f0ce96341babd17c8176", "address": "", "csrfmiddlewaretoken": "e8L8dH7bsheQgf2un1ORvVDQieyuoiCN", "email_address": "", "type_of_user": "individual"}

There were two line feeds between "no and not yet", like

"no

not yet"

The stuff after the line break is where the console marked the error, like this: fobi_error

@bum2 is that what you are seeing?

bhaugen commented 8 years ago

@bum2 how much of the javascript at the top of the "work/joinaproject_request.html" template came from fobi and how much did you add? I'd like to isolate anything that might be a fobi bug.

[edit]: where did decodeHTMLEntities come from? I can't find it in fobi. It might be the source of the bug.

Re the placement of the captcha, if that's your code positioning it in javascript, the html field-by-field way is a lot more reliable.

bhaugen commented 8 years ago

where did decodeHTMLEntities come from? I can't find it in fobi. It might be the source of the bug.

I commented out both of the str.replace statements in that function and the syntax error still happened.

bhaugen commented 8 years ago

I haven't made any headway in solving the problem, although I did a lot of tinkering.

@bum2 did you find code examples for the fobi form handling in work/views/joinaproject_request and the work/joinaproject_request.html template? Anywhere in the fobi repo? I didn't find much, but maybe I was looking in all the wrong places...

bhaugen commented 8 years ago

Ok, I might have fixed it. Pushed a simple change from escape to escapejs that seems to have worked. @bum2 please test locally when you get a chance.

bum2 commented 8 years ago

The fix works great @bhaugen , thanks!