Zoinky
Zoinky

Reputation: 5029

Blazor - textarea bound to oninput, but not being called when the value of text area changed with javascript

I have a textarea bound as below

<textarea id="markdownEntry" class="w-100 h-100" bind="@MarkdownContent"
                      @bind-value="MarkdownContent"
                      @bind-value:event="oninput"                       
                      placeholder="Enter markdown here..."></textarea>

but I would like the oninput to fire when the value of the text area is updated with javascript as well (needed to create a editor) I tried the following js but doesnt seem to work

function forceUpdate(input) {

    var event = new Event('input');
    input.dispatchEvent(event);
}

I also tried changing input to change

Upvotes: 2

Views: 2088

Answers (1)

Zoinky
Zoinky

Reputation: 5029

function forceUpdate(input) {

    var event = new Event('input', {
        'bubbles': true,
        'cancelable': true
    });
    input.dispatchEvent(event);

}

Fixed the issue

Upvotes: 3

Related Questions