Making jQuery selector/contains case insensitive
Posted by mkhairul - November 26, 2008 at 03:11:49 pm - No CommentsCategories: Troubleshoot, blog, code
Just another stuff from work. There’s huge list to select people to be put into groups in the LMS. I added a javascript function for the user to type in a name and it will search and select a user in the list box.
I use Selector/contains for this but the problem is, it is case sensitive. That’s gonna be a problem to type in the exact case from the list. Here’s a snippet to extend the selector.
jQuery.extend(
jQuery.expr[':'], {
contains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0"
});
Took the snippet from StackOverflow, but it has a typo.
CodeIgniter 1.7 DBForge Error (Array to string conversion error)
Posted by mkhairul - November 20, 2008 at 11:11:13 am - No CommentsCategories: Troubleshoot, blog, code, php
I think the ellislab team is swamped with bug reports and stuffs. But I’m sure the next release will solve this problem.
I found this solution at the forum, CI 1.7 Forge Problems. Basically what you need to do is find DB_driver.php inside the database folder. Go to function _protect_identifiers (most probably on line 1193).
Add in this code (inside the function).
if (is_array($item))
{
$array = array();
foreach($item as $one)
{
$array[] = $this->_protect_identifiers($one, $prefix_single, $protect_identifiers, $field_exists);
}
return $array;
}
Alright, that should fix it up.
Adding confirm dialogue box for delete links with jQuery
Posted by mkhairul - November 15, 2008 at 01:11:33 am - No CommentsCategories: Tips, blog, code
I use this all the time. Its simple, clean and gracefully degrades. Even though its simple some people might miss it. So I post it here.
$('.delete').click(function(){
if(!confirm('Are you sure you want to delete?'))
{
return false;
}
})
By returning false you stop any action from the link (redirecting you to the url)
You can see the demo here.
Debugging an SQL Query
Posted by mkhairul - November 12, 2008 at 11:11:26 pm - No CommentsCategories: Tips, Troubleshoot, blog, code
So, I debugged an error for a good friend recently. Only certain kind of item would be displayed, everything else was not found in the search. The first thing I suspect is the SQL Query. I printed out the SQL Query and tried to debug it.
The first thing I did is to arrange the SQL Query in a readable manner.
Since I do not have the time to follow the trail from the SQL Query manually, I just comment out 3 conditions at a time, and add a condition each time until the item was found. In the above picture, I’ve found the culprit its the one below the commented out line.
When I commented out the line, the results for the keyword appeared as follow.
So thats the divide and conquer part. So now I know the problem is with the commented out criteria and the one below it. I traced it back to its table (products_to_categories) and found out that the category_id value is empty. Thats why it can’t join in with the categories table and thus there’s no result.
So what did I do? I told my friend about the problem, explained it to him (I gave him a couple of screenshots to explain the problem) and gives him a solution. UPDATE products_to_categories SET categories_id = xx. So that all the item have a category and will be displayed when it is searched by the application.
Erm, yeah. Thats about it.
Check for valid date
Posted by mkhairul - September 11, 2008 at 12:09:57 am - 2 CommentsCategories: blog, code, php
Maybe I’m missing something here. I really think something like this already exist out there. Could not find it so I tried my own.
$pattern = '/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/';
$subject = array();
$subject[] = '30/04/2008'; // valid date
$subject[] = '/30/2008'; // invalid format
$subject[] = '111/30/2008'; // invalid format
$subject[] = '04/30/2008'; // invalid date
foreach($subject as $item)
{
preg_match($pattern, $item, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
if($matches)
{
list($day, $month, $year) = split('/', $item);
if(!checkdate($month, $day, $year))
{
print "
invalid date: $item";
}
}
else
{
print '
invalid format';
}
print '
';
}
Retrieve the content of FCKEditor
Posted by mkhairul - September 10, 2008 at 10:09:28 am - No CommentsCategories: Tips, code
Here’s an interesting problem that I faced few days ago on MyQuotes. I wanted to apply a lightbox kind of preview for the content the user put in. I use FCKEditor for the textarea. I have no idea how to retrieve the contents from the textarea (to put it into the lightbox).
After googling around ( I forgot the keyword that I used ), I found it, it can be retrieved using FCKEditor’s API.
oEditor = FCKeditorAPI.GetInstance('quote');
myValue = oEditor.GetXHTML(oEditor.FormatOutput);
The FCKEditor is using BBCode, to minimize abuse (hope it works! LOL). Since I don’t know how to convert the bbcode values retrieved from the content into HTML tags, I use the next best thing. Send it to be converted and tagged up using jQuery’s $.post().
Focus on first input text in jQuery
Posted by mkhairul - September 4, 2008 at 01:09:46 am - No CommentsCategories: Development, Tips, code
I’m doing a little bit of polishing while finishing up some forms. I got this fade-in effect and wants to get the first input text to be focused when the animation ends.
function show_form(formname)
{
hide_all();
$('#' + formname).css('opacity', 0).parent().show();
$('#' + formname).animate({opacity: 1}, 'normal', function(){
// focus on the first input in the form
$('#'+formname+' input:text:first').focus();
offset = $('#add_new').offset().top;
$('html, body').animate({
scrollTop: offset }, 2000);
});
return false;
}
There’s an additional effect in that function. It’ll scroll down to the form because there’s a list above the form, so, it’ll just scroll right pass it.
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.




