Posts Tagged ‘Javascript’

Codepress Does Not POST Text Entered Into <textarea>

Tuesday, October 6th, 2009 by The BCM Team

We are using Codepress for the administrator application within our custom CMS.

Codepress is a web-based source code editor with syntax highlighting written in JavaScript that colors text in real time while it’s being typed in the browser.

We have been very happy with it so far except one little hiccup that we came across when we were integrating it into the CMS: the forms where Codepress was hooked up to were not submitting any entered content for the Codepress enabled form fields. The values were not just set to empty strings in the POST, they were actually missing.

For example, lets say we have a form with the following elements:

  • Name – text field named “name”
  • Description – textarea with Codepress functionality enabled named “description”
  • Submit – button

After entering any content into Name and Description and submitting the form, POST will only have one form related variable in it – “name”. As I mentioned before the “description” variable is not just empty, it isn’t not included in the POST array at all. And here ’s why:

When Codepress gets hooked up to a form’s textarea element, it hides it and creates an iframe that supports all of the bells and whistles like syntax highlighting etc. Not only does it hide the original textarea but it also modifies DOM and removes any textarea’s ID so it does not get added to a form submission via POST. This explains why the textarea content is fully excluded from the POST.

To fix this you need to tell the form to copy the value from Codepress’s iframe (that the user types in) into the original form’s textarea. The best time to do this, is just before the form gets submitted by assigning this action to the form’s submit button on-click event, for example.

Here is the example of how to do it:

<textarea id="code" onclick="code.toggleEditor()" name="code" ... </textarea>
<input type="submit" onclick="code.toggleEditor()" value="Submit"/>

Note the values of the id and name attributes of the textarea. They are set to “code” so we can reference the textarea by “code” when making a “code.toggleEditor()” call.

You can download Codepress from its dedicated site at sourceforge.net.

Codepress in action

Codepress in action

Symfony: Ajax.Autocompleter is not a constructor

Sunday, January 4th, 2009 by The BCM Team

If you use Symfony and its Autocomletion feature, you may get the following error: "Ajax.Autocompleter is not a constructor"
There could be two reasons for this:

  1. Necessary JS libraries are not loaded. To fix make sure you load the following libraries (example below is for including them from the action):
    
    $response->addJavascript('/sf/js/prototype/prototype');
    $response->addJavascript('/sf/js/prototype/effects');
    $response->addJavascript('/sf/js/prototype/controls');
    
    
  2. You could be including Prototype JS library twice. So for the example above I am adding a prototype JS library. In addition to that I could have added it to be added in the view.yml file. This would have caused the "Ajax.Autocompleter is not a constructor".

Useful jQuery snippets

Monday, December 29th, 2008 by The BCM Team

Enable debug menu in Safari for Windows and Mac OsX

Sunday, April 6th, 2008 by The BCM Team

To enable a debug menu in Safari browser for Windows do the following:

Windows

Add a key/value pair <key>IncludeDebugMenu</key><true/> before the closing </dict> to the following Safari configuration file:

  1. Windows XP/2000 C:\Documents and Settings\<USERNAME>\Application Data\Apple Computer\Safari\Preferences.plist

  2. Windows Vista C:\Users\<USERNAME>\Application Data\Apple Computer\Safari\Preferences.plist

and restart Safari.

Mac OsX

Run the following command in terminal:


defaults write com.apple.Safari IncludeDebugMenu 1