Problems with dojo javascript library
Permalink
I built a custom block, which is a form. The form contains dojo widgets and css ... all is well. I can add the block to my page, and the form's view is great...the form submits to my php file and does what I want.
The problem is: when I add the same block to the same page more than once, the 2nd block doesn't obtain the css, nor does the submit button work (or any functionality of the form whatsoever). Mnkras was helping me a bit, but I felt this was worthy of a forum post.
His initial thoughts were that the js was getting populated to the header more than once. That isn't the case. My dojo/js isn't in the header at all actually.
Any other thoughts?
The problem is: when I add the same block to the same page more than once, the 2nd block doesn't obtain the css, nor does the submit button work (or any functionality of the form whatsoever). Mnkras was helping me a bit, but I felt this was worthy of a forum post.
His initial thoughts were that the js was getting populated to the header more than once. That isn't the case. My dojo/js isn't in the header at all actually.
Any other thoughts?
JimboJetset: I'm pretty sure you are right. I created a test website using an Apache VirtualHost and copied/pasted my code with dojo/js in the index.php file twice. I thought about that issue too, so I renamed all of the elements in the second form and it worked.
This is definitely possible, but another road to go down: is it including the libraries in the page more than once? ie are you using addHeaderItem() to add the javascript/css to the page's header (just once) or are you just including it in the view template?
None of my dojo is being placed in the header. I have copied and pasted all of the code via my page source and used pastebin for your viewing (see link below). If you'd like to see the contents of <head> let me know.
http://pastebin.org/245606
http://pastebin.org/245606
don't really know dojo but i can tell you that there's a lot of weird stuff going on in there. There shouldn't be any body tags there but I see two of them (the body tag should start further upon the page, right after the header tag closes). That could definitely cause a large number of issues. There are probably some other odd things going on.
yeah, I know...if I don't define the class of the body, though, I lose the styling. I don't know how to get around that.
andrew, I'd like to try editing my code a bit...how do I put things into the header using addHeaderItem()?
Now the question is... how do you get round this in C5...
What I've done in the past is use addHeaderItem() in my block controller to write (longhand) my CSS & JS directly into the header (as code rather than linking to a static file) whilst appending the unique block ID to the end of each CSS element and each call to that element from the JS. It's not ideal.. especially if you have a large amount of JS and/or CSS but it does solve the 'uniqueness' issue.
What I've done in the past is use addHeaderItem() in my block controller to write (longhand) my CSS & JS directly into the header (as code rather than linking to a static file) whilst appending the unique block ID to the end of each CSS element and each call to that element from the JS. It's not ideal.. especially if you have a large amount of JS and/or CSS but it does solve the 'uniqueness' issue.
Well, I thought about how to overcome this for a few minutes and I'm not sure it's that easy. Let's say that the concrete5 page does get "fixed" with your suggestions...I still have an issue. The form's action is a php file, and that php file has variables like $stuff=$_POST['stuff']; (pretend that is a textbox in form 1). Well, if form 2 has a different element name or ID, the action file renders useless...
Or, are you saying there is some way to have the same form/block on the page with the same name/ID? If that is the case, saweet! I would definitely need someone's help with writing the workaround code as I'm not a javascript, php, or c5 genius. I'm trying to learn a little of each as I go.
Or, are you saying there is some way to have the same form/block on the page with the same name/ID? If that is the case, saweet! I would definitely need someone's help with writing the workaround code as I'm not a javascript, php, or c5 genius. I'm trying to learn a little of each as I go.
Ask yourself this... would the user NEED to have multiple copies of your custom block on the same page...?
...and no... you should not have two forms with the same name or id's on the same page...
...as for the post variables... if you use the blockID to help identify different element names then just have the revceiving .php file strip the blockID off the end. You could easily use a regular expression for this.
I'm not familiar with exactly what you are trying to do so I can only offer broad options rather than specific solutions.
...and no... you should not have two forms with the same name or id's on the same page...
...as for the post variables... if you use the blockID to help identify different element names then just have the revceiving .php file strip the blockID off the end. You could easily use a regular expression for this.
I'm not familiar with exactly what you are trying to do so I can only offer broad options rather than specific solutions.
I've already asked myself whether users will need the block more than once on a page. My thoughts were 'no way'. But, my buddy who is working on this project with me thinks it may be possible. I'll talk with him again. I don't want to go down this path unless absolutely necessary!
Could this issue of identification be where your problem lies...?