Permalink
Browse files

Fix caret right away, in case of lazy initalization

  • Loading branch information...
1 parent 0f13f96 commit 61b0a7b54da969c9710c3cb983bbdee2428b160b Jeff Johnson committed Mar 14, 2013
Showing with 6 additions and 1 deletion.
  1. +3 −0 jquery.moneyfield.coffee
  2. +3 −1 jquery.moneyfield.js
@@ -19,8 +19,11 @@ $.fn.extend \
$(this).keyup update_value_field
# Set initial value
+ cursor_pos = $(this).caret().start;
$val = get_value_field.call(this)
$(this).val(convert_actual_to_friendly.call($val, opt.prefix))
+ $(this).caret(cursor_pos,cursor_pos)
+
this
@@ -15,14 +15,16 @@
var opt;
opt = $.extend(defaults, params);
return this.each(function() {
- var $val;
+ var $val, cursor_pos;
if ($(this).data('money-field')) {
return this;
}
$(this).data('money-field', opt);
$(this).keyup(update_value_field);
+ cursor_pos = $(this).caret().start;
$val = get_value_field.call(this);
$(this).val(convert_actual_to_friendly.call($val, opt.prefix));
+ $(this).caret(cursor_pos, cursor_pos);
return this;
});
}

0 comments on commit 61b0a7b

Please sign in to comment.