OnEditChanged for textfields moves the cursor ...

Started by Peter2, January 03, 2018, 03:29:10 AM

Previous topic - Next topic

Peter2

I have a simple textfield where I enter values, e.g "123"
I have a second textfield where the result of "inputvalue x 2" should be displayed, e.g. 246 (the result of 123x2)

On field A a have the event "OnEditChanged" which runs the calculation "input x 2".

Sounds great, but the problem is in detail, e.g. for "123"
- I press "1"
-> It calculates 1x2=2 and displays 2
-> It returns to field "A" and sets the cursor on the beginning of the field
- I press "2"
-> Instead of expected value "12" in field "A" I have now "21", because 2 was entered at the beginning of the field.

What to do to keep the normal order of the input - 123?

Happy new year to all!
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

What exactly does your OnEditChanged event handler do, and what does it return?
Owen Wengerd (Outside The Box) / ManuSoft

Peter2

#2
Hi Owen

here is the code:

(defun c:rbi_drawscale/bildskalierung/faktor#OnEditChanged (strNewValue /)
    (setq faktor (abs (atof strNewValue))
          soll (* faktor ist))
    (dcl-Control-SetText rbi_drawscale/bildskalierung/faktor (rtos faktor 2 3))
    (dcl-Control-SetText rbi_drawscale/bildskalierung/eff_distanz (rtos soll 2 3))
    ; Aushren-Button (de)aktivieren
    (if (and soll ist faktor)
        (dcl-Control-SetEnabled rbi_drawscale/bildskalierung/ausfuehren t)
        (dcl-Control-SetEnabled rbi_drawscale/bildskalierung/ausfuehren nil)
    )
)

https://www.screencast.com/t/ia7bZOaTJpEZ
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

It seems risky to change the notifying control's text from the OnEditChanged notification. If you must change the text, then you also need to manage the caret position. I think you should remove this line altogether:
(dcl-Control-SetText rbi_drawscale/bildskalierung/faktor (rtos faktor 2 3))
Owen Wengerd (Outside The Box) / ManuSoft

Peter2

Thanks Owen - fixed.

(I don't know why I had the idea to use this line ...)
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10