Recent

Author Topic: TEdit idea  (Read 1901 times)

SteveSS

  • New Member
  • *
  • Posts: 43
TEdit idea
« on: September 11, 2019, 03:19:39 pm »
Hi All.  When using the on change in a TEdit, it is very unlikely that your code could proceed the first time the event is fired.  If entering a name, John Smith for example, the on change fires as soon as the 'J' is typed.  I get round this by using the on change to start / re-start a timer and when the timer fires (after two seconds) you can be pretty sure the user has finished entering the whole of the TEdit field.

When I was working as a Delphi prorammer, we used something called JF Controls - these were essentially a replacement for the Delphi GUI, with a few extra bells and whistles.  One of these was a property on the TJfEdit called timechange, set in milliseconds, which did exactly as I have described above i.e. providing a timer to determine that the on change event had actually finished.

Any of you Lazarus Development Heros fancy adding such a property to TEdit?  Or maybe there is another way of using the existing GUI that I haven't discovered yet.

Steve

andresayang

  • Full Member
  • ***
  • Posts: 108
Re: TEdit idea
« Reply #1 on: September 11, 2019, 03:31:58 pm »
Hi,

You should user "onEnter" - "onExit" or "OnEditingDone" (The latest will fire when you validate or move to next one after being entered)
But make sure your TEdit is not the first control receiving focus when form is created (if using onEnter)

OnChange is fired each time TEdit change, so if you type something inside, It is changed.
.


Cheers
« Last Edit: September 11, 2019, 03:43:16 pm by andresayang »
Linux, Debian 12
Lazarus: always latest release

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TEdit idea
« Reply #2 on: September 11, 2019, 03:36:56 pm »
When using a timer with a TEdit
you can be pretty sure the user has finished entering the whole of the TEdit field.

When using the edit's OnEditingDone event you can be absolutely sure the user has finished entering the whole of the TEdit field. And you don't need a timer.

SteveSS

  • New Member
  • *
  • Posts: 43
Re: TEdit idea
« Reply #3 on: September 11, 2019, 03:51:39 pm »
Thanks for the replies.  I will have a try with oneditingdone, but what if you are entering, say 4 tedit boxes then enabling an 'UPDATE' button if the data is ok?  The user would have to click somewhere after the 4th tedit to trigger validation - doesn't seem very intuitive as far as the use is concerned.

Steve

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: TEdit idea
« Reply #4 on: September 11, 2019, 04:11:34 pm »
Thanks for the replies.  I will have a try with oneditingdone, but what if you are entering, say 4 tedit boxes then enabling an 'UPDATE' button if the data is ok?  The user would have to click somewhere after the 4th tedit to trigger validation - doesn't seem very intuitive as far as the use is concerned.

Steve
How do you figure that?
Your user inputs text in Text1, and then MOVES to Text2 (Clicking or tabbing there), which in itself fires OnExit/OnEditingDone for text1.
So when he reaches Text4, edits it, and then clicks on his button you expect what?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TEdit idea
« Reply #5 on: September 11, 2019, 04:50:42 pm »
When grouping edits like that I've used the TAG property per edit control as a flag point to indicate good or bad, this can he updated in the OnChange if you wish which means it must test the input for validation each keystroke.

 While in that event you can call a master Function that test against all 4 edits..

  UpdateButton.Enabled := AreALLFourceEDITSValid;

 put that in each OnChange event.

 Or of there is some weird issue going on, put that in the OnEditingDone event except for the last one.

 In any case the UPDATE button will enable itself.

 Its all about coding practices .
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: TEdit idea
« Reply #6 on: September 11, 2019, 05:15:50 pm »
Thanks for the replies.  I will have a try with oneditingdone, but what if you are entering, say 4 tedit boxes then enabling an 'UPDATE' button if the data is ok?  The user would have to click somewhere after the 4th tedit to trigger validation - doesn't seem very intuitive as far as the use is concerned.

Steve

Well, yes for the 4th button OnEditDone does not work, if in the event you want to execute "ButtonFoo.enabled := true;"
(actually not sure, if "not enabled" includes can not have focus....)

You don't really want a long timer either. As a user, if I typed e.g. my name, I might (want to) hit "tab" immediately. But if the button is not enabled, then where will tab get me to.

One option is to have the button enabled, but pop up an error, if validation fails. Then validation happens in the button.
That of course is a different flow from what you want....

Now do validate as the user types, it depends how much computing validation takes.
If you just need to know if a cell number matches a pattern, then you can do that on every stroke.
You can also shortcut testing, if a minimum length has not been reached yet.

If computing takes longer, you can use Application.QueueAsync... or move it to a thread.
But you would validation need to
- check regularly if it needs to restart (input changed)
- in case of async, running in the main thread: validation needs to give way. That is it needs to store howfar it got, interrupt itself, and continue in a new async event.

Using a timer you have the same issues.
Imagine validation takes 2 seconds or longer.
The use paused typing for just long enough to trigger validation. But now he wants to continue, and the app does not react, as validation is blocking it.....

Either way:
If validation is quick -> do it directly in OnChange
If it is slow, then think about what happens if the user wants to tab to the button.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: TEdit idea
« Reply #7 on: September 11, 2019, 05:18:45 pm »
Normally I don't use OnEditingDone because it checks a single control only. What can be in error at one moment of the program flow may be correct when other controls are filled in correctly. I also think that checking in OnChange is a nightmare because to user is aways distracted from typing with every typo; he is not even allowed to use Backspace or DEL. Therefore, I usually check validity only when the action using all these parameters is executed, i.e. when the modal form is closed, or when a "Run" or "Execute" button is pressed.

In order to validate all input controls I write a validation function, ValidData, ValidInput or so which checks each control and prepares an error message. It also returns the control which has the error so that it can be refocused to signal the user which control needs reconsideration.

Try attached demo. It contains three TEdit controls: the first one accepts only an integer, the second one only alphanumeric characters, and the third one only a valid date. Press the button when at least one of these conditions is not met.

----

I really would hate the timed input - too much stress!
« Last Edit: September 11, 2019, 05:20:54 pm by wp »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: TEdit idea
« Reply #8 on: September 11, 2019, 05:52:36 pm »
I also think that checking in OnChange is a nightmare because to user is aways distracted from typing with every typo; he is not even allowed to use Backspace or DEL.

Depends on what and how you check.

If the only feedback of the check is, that the "submit" button becomes enabled/disable, then you can type on.

Many webpages do that for passwords during registration, where a label changed between: weak, medium, strong.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TEdit idea
« Reply #9 on: September 11, 2019, 05:56:49 pm »
I usually do validation on one single pass.

I like finding new programs and testing them. I remember I got a simple program, which may be useful to me. Unfortunately, it was too annoying.

Not remember clearly, but something like this. If I click the ok button on a dialog box, it told me I provided wrong data for the no # input box. Okay, I went there, fixed it and clicked the ok button again. It then told me the same thing but on different input box. Again and again until I really passed all the validation check for all the input boxes.

At that moment, I was learning WordPress. So, that made me think. WordPress and all of its plugins usually have not only good looking interface, they also has good UX design. At least, it won't nag you like you're a child when you did something wrong. It will present a list of things that you need to fix.

My 2¢.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: TEdit idea
« Reply #10 on: September 11, 2019, 06:38:04 pm »
it won't nag you like you're a child when you did something wrong. It will present a list of things that you need to fix.
Nothing's perfect.

When there are many errors (at least so many that moving between button and input control happens becomes annoying) then the list wil be long. What happens with this list? Hopefully it is not displayed in a modal window -- this would force you to close it in order to get back to the faulty input control, but then you'd have to press the button again to bring the list back on the screen. Another bad scenario is that which everybody sees when HeapTrc is active in a Lazarus program and there are many memory leaks... In the best case, the list appear in a single non-modal window which does not cover relavant parts of the form.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: TEdit idea
« Reply #11 on: September 11, 2019, 07:29:23 pm »
Not sure about the others (Joomla, Drupal, etc). But WordPress rarely uses modal window. They usually show the warning/error messages as a footer or header.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: TEdit idea
« Reply #12 on: September 11, 2019, 09:32:08 pm »
Not sure about the others (Joomla, Drupal, etc). But WordPress rarely uses modal window. They usually show the warning/error messages as a footer or header.
Drupal +1

 

TinyPortal © 2005-2018