michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
337 stars 71 forks source link

Scroll URL inputs to the right #243

Open szepeviktor opened 8 years ago

szepeviktor commented 8 years ago

Could we have a new field attribute 'scroll_right' => true that fires this JavaScript on the input field?

var foo = document.getElementById("foo");
foo.value = "http://stackoverflow.com/questions/1962168/scroll-to-the-very-right-of-a-long-text-input";
foo.focus();
foo.setSelectionRange(foo.value.length,foo.value.length);
szepeviktor commented 8 years ago

And maybe foo.blur() afterwards.

szepeviktor commented 8 years ago

Use case: in general the URL's beginning is always the same, the end will tell you something.

michaeluno commented 8 years ago

Good idea.

michaeluno commented 8 years ago

I posted a sample plugin which includes a custom field type implementing this feature.

You can simply click on the Download link in the following page to get the plugin. https://gist.github.com/michaeluno/d2e32c98f5bf710078ad

Please test it and see if any problems exist. Then it can be included in the core.

By the way, setSelectionRange() did not work in Chrome v35.