how can I select text in input field in TypeScript.
in Javascript this wpuld look like this:
document.getElementById('id').select();
but TypeScript does not support select (error: [ts] Property 'select' does not exist on type 'HTMLElement'.)
Added a few think: It may be a problem beacouse I use dx controls and they create a wraper. You can see here in html:
<dx-text-box _ngcontent-c1="" id="test" ng-reflect-disabled="false" ng-reflect-value="0:00" class="dx-texteditor dx-widget dx-textbox">
<div class="dx-texteditor-container">
<input autocomplete="off" class="dx-texteditor-input" type="text" spellcheck="false" tabindex="0" role="textbox">
<div data-dx_placeholder="" class="dx-placeholder dx-state-invisible"></div><div class="dx-texteditor-buttons-container">
</div></div></dx-text-box>
document.getElementById(string)
returns an HTMLElement
which does not define a select()
method. HTMLInputElement
DOES define a select()
method and also extends HTMLElement
, so if you cast as HTMLInputElement
, it should work:
(document.getElementById('id') as HTMLInputElement).select();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With