Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in javascript code? #16

Open
MPorte opened this issue Dec 31, 2012 · 5 comments
Open

Error in javascript code? #16

MPorte opened this issue Dec 31, 2012 · 5 comments

Comments

@MPorte
Copy link

MPorte commented Dec 31, 2012

Hello,

It's seems to be a mistake in the javascript code in edit template

$(function() {
new PunkAveFileUploader({
'uploadUrl': {{ path('upload', { editId: editId }) | json_encode | raw }},
'viewUrl': {{ '/uploads/tmp/attachments/' ~ editId | json_encode | raw }},
'el': '.file-uploader',
'existingFiles': {{ existingFiles | json_encode | raw }},
'delaySubmitWhileUploading': '.edit-form'
});
});

the lign : 'viewUrl': {{ '/uploads/tmp/attachments/' ~ editId | json_encode | raw }}, doesn't work on my project.

I had to replace it by 'viewUrl': '/uploads/tmp/attachments/{{ editId | json_encode | raw }}',

I'm using :
jquery-1.8.3.js
query-ui-1.9.2
Symfony 2.1.7

@boutell
Copy link
Member

boutell commented Jan 2, 2013

The original code is working in our projects. Your suggested code would result in a busted string with extra backticks:

'viewUrl': '/uploads/tmp/attachments/'555555''

Because you are using the json_encode filter inside something that is already a quoted string.

Are you getting a javascript error with the original code? Can I see that?

@MPorte
Copy link
Author

MPorte commented Jan 2, 2013

Yes you are right the editId seems to be quoted.

'viewUrl': /uploads/tmp/attachments/"853341266",
the error is "Uncaught SyntaxError: Unexpected identifier",

my variables was send, by this way :

return array(
'existingFiles' => $existingFiles,
'editId' => $editId,
'entity' => $entity,
'categorie' => $categorie,
'form' => $form->createView(),
);

So I tried to convert $editId into numerical type, I changed
'editId' => $editId by 'editId' => intval($editId)

But now I get the following result :
'viewUrl': /uploads/tmp/attachments/1524605743,

error is now "Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'tmp' "

editId is generated by the way you said. I don't understand what is wrong.

@delocker
Copy link

Replace this
'viewUrl': {{ '/uploads/tmp/attachments/' ~ editId | json_encode | raw }},
with this
'viewUrl': "{{ '/uploads/tmp/attachments/' ~ editId | json_encode | raw }}",

@boutell
Copy link
Member

boutell commented Jan 12, 2013

That will result in a JSON-encode, quoted string inside another set of
quotes.

If there is a bug here (and I am not convinced there is, because my uploads
are working) this is not the fix.

On Fri, Jan 11, 2013 at 7:37 PM, Egor notifications@github.com wrote:

Replace this

'viewUrl': {{ '/uploads/tmp/attachments/' ~ editId | json_encode | raw }},
with this

'viewUrl': "{{ '/uploads/tmp/attachments/' ~ editId | json_encode | raw
}}",

Reply to this email directly or view it on GitHubhttps://github.com//issues/16#issuecomment-12170386.

Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com

@mar1naj
Copy link

mar1naj commented Mar 1, 2013

This was my solution:

'viewUrl': {{ '/uploads/tmp/attachments/#{editId}' | json_encode | raw }},

@benhei
Copy link

benhei commented Aug 10, 2013

I have a very similiar issue.

Using your code snippets I get:

$(function() {
new PunkAveFileUploader({
'uploadUrl': "/Symfony/web/app_dev.php/userhome/employees/upload?editId=285944417",
'viewUrl': /uploads/tmp/attachments/"285944417",
'el': '.file-uploader',
'existingFiles': [],
'delaySubmitWhileUploading': '.edit-form'
});
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants