Skip to content

Commit

Permalink
set target value onchange client-side (#694)
Browse files Browse the repository at this point in the history
* set target value onchange client-side

This may not be a perfect solution. I worry that doing this may have unintended
consiquences. For example, what if someone wanted to have some sort of
auto-correct feature. Will setting the target value somehow overwrite
auto-corrections? From limited testing it seems to work fine, but that
testing was not extensive.

* changelog entry
  • Loading branch information
rmorshea authored Feb 28, 2022
1 parent 78f33ff commit fddd1d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/source/about/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ scheme for the project adheres to `Semantic Versioning <https://semver.org/>`__.
Unreleased
----------

Nothing yet...
Fixed:

- ``onChange`` event for inputs missing key strokes :issue:`684`


0.37.0
Expand Down
10 changes: 8 additions & 2 deletions src/client/packages/idom-client-react/src/element-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ export function createElementAttributes(model, sendEvent) {

if (model.eventHandlers) {
for (const [eventName, eventSpec] of Object.entries(model.eventHandlers)) {
attributes[eventName] = createEventHandler(sendEvent, eventSpec);
attributes[eventName] = createEventHandler(
eventName,
sendEvent,
eventSpec
);
}
}

return attributes;
}

function createEventHandler(sendEvent, eventSpec) {
function createEventHandler(eventName, sendEvent, eventSpec) {
return function () {
const data = Array.from(arguments).map((value) => {
if (typeof value === "object" && value.nativeEvent) {
if (eventSpec["preventDefault"]) {
value.preventDefault();
} else if (eventName === "onChange") {
value.nativeEvent.target.value = value.target.value;
}
if (eventSpec["stopPropagation"]) {
value.stopPropagation();
Expand Down

0 comments on commit fddd1d8

Please sign in to comment.