doorman
doorman

Reputation: 16969

Disabling undo/redo in an HTML input field

I am using asp.net input fields and they automatically provide undo/redo functionality. I am using JavaScript to format the value of the input field, however this ruins the undo/redo history.

Upvotes: 4

Views: 3628

Answers (2)

Atomenergy
Atomenergy

Reputation: 1

I come up with this idea to remove the Undo/Redo to an input field using DOM manipulation and cloning, but make sure that the input is inside a parent node, this approach appends the newly cloned input field

I call this method on "onchange" event of the input... this is just a hack though.

function decup(e){

    let new_ =  e.target.cloneNode();
        let parent_N = e.target.parentNode;
            e.target.remove();
            parent_N.appendChild(new_);                     
        console.log(parent_N);

}

Upvotes: 0

Jonathan Wilson
Jonathan Wilson

Reputation: 4305

Using JavaScript, try replacing the text field with a new one and then setting the value. New field, new undo buffer, right?

jQuery:

$('#theTextField').after('<textarea id="theTextField2"></textarea>').remove();
$('#theTextField2').attr('id','theTextField');

Upvotes: 3

Related Questions