0

I am trying to implement auto sized text field based on the solution from this question

<input style="width:20px;" onkeypress="this.style.width = ((this.value.length + 1) * 5) + 'px';"  ng-model="questionButtons[$index].title" type="text" class="edt_spn active" >

it works fine however when the user deletes characters width is not adjusting

<input style="width:20px;" onkeypress="this.style.width = ((this.value.length + 1) * 5) + 'px';"  ng-model="questionButtons[$index].title" type="text" class="edt_spn active" >

2 Answers 2

1

Try onkeyup event.

<input style="width:20px;" onkeyup="this.style.width = ((this.value.length + 1) * 5) + 'px';console.log(this.value.length);"  ng-model="questionButtons[$index].title" type="text" class="edt_spn active" >

Sign up to request clarification or add additional context in comments.

Comments

0

I think that the best variant is to use oninput event.

From MDN:

The DOM input event is fired synchronously when the value of an <input>, <select>, or <textarea> element is changed.

<input style="width:20px;"  oninput="this.style.width = ((this.value.length + 1) * 5) + 'px';"  ng-model="questionButtons[$index].title" type="text" class="edt_spn active" >

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.