LearnNewsExamplesServices
Frontmatter
id4818
titleform.field.Checkbox, form.field.Text: Fire userChange event
stateClosed
labels
enhancement
assigneestobiu
createdAtSep 1, 2023, 4:33 PM
updatedAtDec 5, 2023, 1:12 PM
githubUrlhttps://github.com/neomjs/neo/issues/4818
authorpensuwan-k
commentsCount12
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtDec 5, 2023, 1:12 PM

form.field.Checkbox, form.field.Text: Fire userChange event

Closed v8.1.0 enhancement
pensuwan-k
pensuwan-k commented on Sep 1, 2023, 4:33 PM

It would be good to make a distinction between change events that are triggered programmatically or by user input

Ghost
Ghost Sep 1, 2023, 4:39 PM

@tobiu I tried to implement userchange event in Checkbox component's onInputValueChange method:

https://github.com/neomjs/neo/blob/8533de4ad4f96cda296b28858db3a54cbe0b7e96/src/form/field/CheckBox.mjs#L493-L501

But this method also gets triggered when the checkbox value is changed programmatically (e.g. bind). Is there any other way to differentiate user triggered change?

Ghost assigned to @tobiu on Sep 1, 2023, 4:40 PM
tobiu
tobiu Sep 1, 2023, 7:41 PM

you are right: a programmatic change will trigger onInputValueChange () too, since it will update the DOM afterwards.

however: inside the method => if checked === me.checked it should be a programmatic change (since the value already updated before the DOM change) and vise versa. just thinking out loud, needs some testing :)

Ghost
Ghost Sep 4, 2023, 11:56 AM

Just tested the solution:

https://github.com/dztoprak/neo/blob/de72ed5b0a4aa39c0ec06f5b8358fbb0dd564915/src/form/field/CheckBox.mjs#L493-L505

checked has always the opposite value of me.checked, so the condition is never true.

shrutiambekar
shrutiambekar Sep 4, 2023, 1:53 PM

@ThorstenRaab

tobiu
tobiu Sep 10, 2023, 11:24 PM
Screenshot 2023-09-10 at 23 22 29

@dztoprak: just did a quick test. the first 2 changes happened when clicking on the field. opposite value for this one.

when programmatically changing the checked state, onInputValueChange() does not trigger at all for me. so we could just always fire a custom event in there. needs testing :)

tobiu
tobiu Sep 10, 2023, 11:28 PM

looks the same way for TextFields:

Screenshot 2023-09-10 at 23 30 50

Ghost
Ghost Sep 14, 2023, 2:42 PM

For me, the onInputValueChange is triggered by all programmatic changes in checkboxes. I haven't tried with the text fields though:

https://github.com/neomjs/neo/assets/126246513/902d9a2b-dd98-41f0-a8fa-a5ebedadf3c7

tobiu
tobiu Sep 14, 2023, 3:01 PM

careful deniz: IF you are clicking on one checkbox to change the checked state of a different one, you will get onInputValueChanged() for the one you clicked on :)

try what i did => control + right click on a checkbox. store it inside a global var. then change the checked state inside the dev tools.

Ghost
Ghost Sep 14, 2023, 3:43 PM

good point, checkbox controllers are not exempt from the checkbox logic of course 😄

Ghost
Ghost Sep 14, 2023, 4:44 PM

@tobiu do you know how can I access the oldValue in Text's onInputValueChange method?

tobiu
tobiu Sep 14, 2023, 4:46 PM

sure. before setting this.value, you can access this.value or this._value to get the old value :)

Ghost cross-referenced by PR #4905 on Sep 14, 2023, 5:14 PM
tobiu referenced in commit a12038c - "form.field.Checkbox, form.field.Text: Fire userChange event #4818" on Sep 14, 2023, 8:31 PM
tobiu referenced in commit 18da892 - "v6.5.3 (#4906) on Sep 14, 2023, 8:41 PM
tobiu
tobiu Dec 5, 2023, 1:12 PM

resolved already.

tobiu closed this issue on Dec 5, 2023, 1:12 PM