set-input-value
Set input value and keep cursor position
Last updated 7 years ago by parshap .
Public Domain · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install set-input-value 
SYNC missed versions from official npm registry.

set-input-value

Set an input's value without losing the user's cursor position.

Example

var set = require("set-input-value");
var input = document.getElementById("my-input");

// Uppercase the value
set(input, input.value.toUpperCase());

// Add a prefix and shift the cursor accordingly
var prefix = "A: ";
set(input, prefix + input.value, prefix.length);

API

set(input, value, shift)

Update the value of the given input element.

  • input: input element to update
  • value: new value
  • shift: amount to shift the previous cursor by (default: 0)

Browser Support

This module currently uses the input.setSelectionRange which is not supported in IE before version 9. A polyfill is possible - see http://jsfiddle.net/EXH2k/6/.

Installation

npm install set-input-value

Current Tags

  • 1.0.0                                ...           latest (7 years ago)

1 Versions

  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (2)

Copyright 2014 - 2016 © taobao.org |