Removing a Select Option in IE using jQuery

I have a selection list, that once selected I would like to remove or disable the option choosen. However, at a later time I may want to add or enable it again.

There is a bug in Internet Explorer that does not allow you to use the .hide() method on an option. It works just find in other browsers of course.

Searching Google I've determined that if I want it hidden in IE, that I would have to use the .remove() method, which removes it from the DOM, store it in an array, and add it back in when needed. I thought this was overkill.

So I found a good solution. The attribute 'disabled' works in IE. Since the hide() method will silently fail, do both. Therefore the option will just not be choosable in IE, and it will disapear in other browsers.


<select>
<option value="">Select One</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<a href="javascript:void(0);">add</a>

<script type="text/javascript">
//do this when the add link is clicked
$('a').click(function() {
//hide or disable the option
$('select :selected').attr('disabled','disabled').hide();
//reset the options back to the top
$('select').val('');
});
</script>

FCKEditor running ColdFusion Stops Working with FireFox 2010 Releases

FCKEditor will stop working with FireFox 3.5.7, 3.6 and future releases. There is a "Year 2010" bug that breaks the regular expression method they use to find what browser you are using. I found this in FCKEditor v.2.6.4.1. ColdFusion 8 and 9 appears to be okay, however I would double check them.

The issues lies in the file fckutils.cfm located in the FCKEditor root install directory. It checks for your useragent such as "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6".

The glitchy code can be found on line 47:


stResult = reFind( "gecko/(200[3-9][0-1][0-9][0-3][0-9])", sAgent, 1, true );

Replace this line with:


stResult = reFind( "gecko/(20[0-9][0-9][0-1][0-9][0-3][0-9])", sAgent, 1, true );

This will give the expression another 90 years of matching. You can also pass "checkBrowser=false" to the FCKEditor component to disable this check.

If you don't have a fckutils.cfm file, a similar line can be found in fckeditor.cfc.

Another "fix" is to upgrade to CKEditor as it's a Javascript only add-on.

Thanks to Pete Freitag for find a fix for this.

EXT JS Designer Preview Finally Released

Awhile back when Ext 3.0 was still being built, I saw a video of an Ext JS designer, which looked similar to Flex Builder. I've been waiting its arival ever since.

Today they released a preview version that allows you to experiment with the designer interface and to explore how configs affect your layout. They say soon you will be able to build your application components using base Ext components and Certified user Extensions. The application is an Air App making it platform independent if you have Adobe Air installed for Windows, Linux, or Mac.

[More]

jQuery with ColdFusion

I've been using the Ext Javascript Framework for awhile now and it's allowed me to present content in a bit more friendly manner. But lately I've been convinced to start into jQuery as well. I'll have the Learning jQuery 1.3 book on its way today too!

Today I ran into a jQuery presentation from the infamous Ray Camden. He presented online for the Connecticut ColdFusion User Group, Intro to jQuery with ColdFusion. He will be presenting an abbreviated version at CFUnited. Check it out here. It seems to be a little choppy, but you should get some usefull info from it with a ColdFusion perspective.

JavaScript Framework Survey

Lately I've been labeled the JavaScript guru around the office. I find that JavaScript Frameworks can make a website user's experience much better, and not too many people would disagree with that. I also tend to use Flex for the same reason. As of current, I extensively use ExtJS (which can replace many features of Flex). Before this, I used to use YUI and JQuery.

Recently Kyle Hayes posted a survey on his blog about JavaScript Frameworks and received over 600 responses. I thought that I would take the time to mention this as it provides some great insight into what other developers think. I hope you find this interesting:

http://www.kylehayes.info/blog/index.cfm/2009/03/29/Survey-Results-JavaScript-Frameworks/

Presentation on Ext using ColdFusion at NECFUG

I put on a presentation at the last Nebraska ColdFusion Users Group meeting. My presentation was recorded and is about an hour-and-half. The quality isn't all that great, so you can view the PowerPoint file here.

Video clips at Ustream

Ext-JS setValue method for ComboBox Control

Trying to set the selected value of a ComboBox control in Ext-JS 2.2, I found out that it was trying to set the selection before it was actually populated. This in-turn appended the value into the ComboBox. Ext's FAQ lists a patch to work around this, but it took some searching to find this solution. You will need to overwrite the setValue method that will listen for the store to be populated.

Ext.override(Ext.form.ComboBox, {
setValue : function(v){
//begin patch
// Store not loaded yet? Set value when it *is* loaded.
// Defer the setValue call until after the next load.
if (this.store.getCount() == 0) {
this.store.on('load',
this.setValue.createDelegate(this, [v]), null, {single: true});
return;
}
//end patch
var text = v;
if(this.valueField){
var r = this.findRecord(this.valueField, v);
if(r){
text = r.data[this.displayField];
}else if(this.valueNotFoundText !== undefined){
text = this.valueNotFoundText;
}
}
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = v;
}
Ext.form.ComboBox.superclass.setValue.call(this, text);
this.value = v;
}
});

AJAX w/ Ext JS

Needing to retrieve just a simple string from an AJAX call using Ext JS and put it inside of a span, here's what I came up with. I am retrieving a single record from XML generated from a ColdFusion CFC.


function updateName(ValueX) {
    if (ValueX) {
        Ext.get("SpanX").update("");
        Ext.Ajax.request({
                         url: 'x_gateway.cfc',
                         params: {method:'getMethodX', name:ValueX},
                         method: 'POST',
                         success: updateContent,
                     failure: function ( result, request) {
                             Ext.MessageBox.alert('Failed', 'There was an error');
                     }
                         });
    }
}

function updateContent(result,request) {
    var readerX = new Ext.data.XmlReader({record: 'record'},
            [{name: 'email'}]);
    
    var resultX = readerX.read(result);
    
    Ext.get("SpanX").update("resultX .records[0].data.email);
}

JavaScript parseDate

When trying to display the proper date, using renderer in ExtJS, from a returned XML document generated by ColdFusion I ran into problems. ColdFusion returns the date from a MS SQL query in a format like this "2008-10-08 14:26:01.0". The standard ExtJS date rendered didn't know how to handle this format so I had to create a custom one.

function renderDate(value){
    var dt = new Date();
    dt = Date.parseDate(value, "Y-m-d h:i:s.0");
    return dt.format('F d, Y');
}

Notice I had to put the ".0" at the end. The result is "Month Day, Year". Otherwise is returns dt as undefined. So the ExtJS data model for that line looks like:


{header: "Date", width: 40, sortable: true, renderer: renderDate, dataIndex: 'date'}

BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner