Latest Post

Error: No input file specified.

While trying to run a codeigniter app the other day I came across this error just after I had finished uploading the files and making the ne...

Saturday, November 30, 2013

ciBonfire - jQuery [Enter] to [Tab]

I started working on bonfire a couple of weeks ago and i must say i'm loving it so far. Being a codeigniter die-hard when i came across bonfire i decided to give it whirl and i have not looked back since.

I recently had to implement a piece of jquery code to prevent users from submitting forms via the [enter] key so what i did is in the specific module/view i added this piece of inline js and viola! my users are happy people now. Find below the code snippet:

$inline  .= '$(document).ready(function() {';
//$inline  .= 'var myinputs = $(":input").not(\'textarea\').not(\'[type="image"]\').not(\'[type="submit"]\');';
$inline  .= 'var myinputs = $(":input").not(\'[type="image"]\').not(\'[type="submit"]\');';
$inline  .= '  myinputs.keydown(function(e) {';
$inline  .= '    if (e.keyCode == 13) {';
$inline  .= '      e.preventDefault();';
$inline  .= '      var current = myinputs.index(this),';
$inline  .= '              next = myinputs.eq(current + 1).length ? myinputs.eq(current + 1) : focusables.eq(0);';
$inline  .= '      next.focus();';
$inline  .= '    }';
$inline  .= '  });';
$inline  .= '});'; 
Assets::add_js( $inline, 'inline' );
This by the way works

No comments:

Post a Comment

Chitika Ads