Restricting a numeric "range" into an input field

Sorry, just trying to help on what I can

Nah nah, that’s fine Alberto. It just took me a while to work out what you were saying.

All good.

Steve, I was thinking about your problem.

I don’t know if it is possible for you to simulate a tooltip/helptag when the user enter a value out of range and they click Update to turn the focus to the angle input and show the warning (maybe even changing the value to 45 if the user entered a lower value or 90 if the user entered a higher value).

Something like the Help Tag:

[quote=422395:@Alberto De Poo]Steve, I was thinking about your problem.

I don’t know if it is possible for you to simulate a tooltip/helptag when the user enter a value out of range and they click Update to turn the focus to the angle input and show the warning (maybe even changing the value to 45 if the user entered a lower value or 90 if the user entered a higher value).

Something like the Help Tag:
[/quote]

Yes Albert, That’s pretty much EXACTLY what what I mean. Thankyou for taking the time to understand my issue. Simulating a tooltip/helptag is easy enough.

After my review, the slider or up/down buttons does not suit my purpose - lots of unnecessary fiddling for the user. Much easier for the user to just input a value, then evaluate as you pointed out:

ABSOLUTELY AGREE - PERFECTO!!!

I wonder if using “Mask” in the IDE would help? Other than that, then it’s algorithm and the code. I’m not sure whether to use the key-down or key-up event to validate the input.

Well, I guess it’s time to just go forward and try/test and see where I get (then ask questions here if/when I fail). Such a small part in my app, but annoyingly complicated.

Maybe this will help

www.rdS.com/restrict_textfield.xojo_xml_project.zip

It is a custom TextField that accepts Only numeric values, and you can set the min/max range
If the user attempts to enter a value outside the supplied range, it will reject the key input
It can also be set to accept Integer Only, or Double values
It also sets the Help Tag as Albert suggested

This can probably be expanded upon, I just put it together as a starting point… for example if you swap the Min / Max values it won’t accept any input (since the input must be >=Min and <=Max

Oh ships! I posted before I saw your post Dave.

Thanks for that.

I’ll blunder around for a while trying different things (which I enjoy) then ask on the forum when I get stuck.

Just as a “heads-up” would it be better to evaluate on key-down or key-up? I’ve never really understood the difference. Normally I’ve used key-up.

check out what I posted… It shows how I think is best to do it

Keydown… you can decide to ignore the keystroke as if it never happened
KeyUp - it has happened, and at best you now have to “undo” something

Thankyou Dave, but I don’t want to TAKE something. Sometimes I like to explore things myself. I don’t expect to spoonfed.

Sometimes I’m happy to blunder around and learn some things for myself, and this is one of them. On other occasions, I’m happy to copy/paste the code and be done with it.

It’s nothing personal, I’d just like to try to sort this out my way. It may well end up that I fail in my quest, and you (and everyone else in this thread) post “I/we already told you so, why didn’t you read it?”… and people get pi**ed off and think I don’t respect or value their opinion/s. That’s far from the truth.

Well nevertheless, I do what I have to do.

[quote=422425:@Steve Kelepouris]Thankyou Dave, but I don’t want to TAKE something. Sometimes I like to explore things myself. I don’t expect to spoonfed.

Sometimes I’m happy to blunder around and learn some things for myself, and this is one of them. On other occasions, I’m happy to copy/paste the code and be done with it.

It’s nothing personal, I’d just like to try to sort this out my way. It may well end up that I fail in my quest, and you (and everyone else in this thread) post “I/we already told you so, why didn’t you read it?”… and people get pi**ed off and think I don’t respect or value their opinion/s. That’s far from the truth.

Well nevertheless, I do what I have to do.[/quote]

He is not spoon feeding you, just showing you how one developer would go about coding this task. We have all learned from code examples in our never ending quest for knowledge. :smiley:

No offense Steve… but if you prefer to blunder around (which I get). then why ASK about it?

I’ve been in this business for more years than I can count, and find I learn more by example than anything else. Do I blindly cut and paste code? No… I study the examples to understand the concepts, and then adapt as required.

I ask, because I don’t know. I may have a rough idea, but I don’t really know.

I gather all the information together then sometimes disregard it, and sometimes go in my own direction. But of course with a better understanding than before.

It seems like I’m being disrespectful, but I’m not.

It’s like 5am here, I will review the posts tomorrow. Sorry if I’ve offended anyone.

Sorry, but I feel it is quite Disrepectful… You ask how to do something, and I take time out of my busy day to provide some insight as to how you migh solve you problem, and you blow it off…

I will refrain from doing so in the future, since this is what you prefer… . I guess your questions should be classified as “rhetorical” then.

Hopefully what I posted might serve as the basis for someone else… but I’m sorry to have wasted your time and mine

Don’t do that Dave. I’m NOT blowing it off!!!. but yes, I can come across as disrespectful, but I’m not.

I just need some time to review it all.

Regarding data validation, here’s what I do:

Every field has 2 boolean values

  • Has been modified
  • Is in an error state

I do as much data validation as possible in KeyDown and inform the user or simply discard keystrokes.

I validate the field in LostFocus. I inform the user of the problem, but let them continue to the next field.

In the form submission button, I evaluate each field that has been modified or is in an error state. If any field fails validation, I inform the user and set focus on the first field that failed. (Note that if the field is being evaluated due to being in an error state, the user has already been informed, so you don’t have to inform them again.)

If all fields pass validation, then I validate the form as a whole - do all the values make sense in relation to each other?

Since field validation occurs in multiple places, each field has a validation event definition, so the code resides in one place and is part of the field itself.

This means, of course, that every field is a custom subclass as is every window. That allows you to have a lot of common code built into the subclass and eases the coding burden. For example, for a TextField, I can tick off the kind of data that is allowed in the field in the inspector.

  • numeric
  • alpha
  • punctuation
  • minus sign
  • hyphen
  • date
  • etc

I don’t have to code the validation for those in each field, it’s already handled by virtue of being a subclass.

Another advantage to this approach is I only have to extract data from the fields that have been modified. That helps reduce potential problems caused by data conversion. It also allows you to decouple the display format of the data from the data entry format. One example of that would be dates - they can be displayed as MM-DD-YY, but entered as MM-DD-YYYY. (I don’t actually do that, but it’s the first example that came to mind.)

I hope that gives you a few ideas.

Is there a way for me to make the forum automatically “like” every post @Tim Hare ever makes? I learn from every single one. Truly, sir, you are a noble spirit and have given generously of your great expertise as long as I’ve been a member here. Thank you.

@Steve Kelepouris if the slider range is too cramped but you still want something very quick and dirty, you can just use a PopUpMenu and populate it with the values - integers 45 to 90 is not that long a list.

@Julia Truchsess you’re making me blush! Thank you for your kind words.

Thanks to Javier, I have been using the autocomplete text field for similar tasks, and added a returnAll method to fill popups and context menus.

I feel blushed too. :slight_smile:

I’m having a bit of a break with coding at the moment and hopefully get back into it soon, otherwise I’ll forget everything.

Although “my” program solution is further than I’ve ever gone (3yrs and ongoing) then I come to the conclusion and face reality that perhaps it will never be finished.???

Maintaining interest and momentum as the days/weeks/months/years go on is becoming a burden.

My first love is Music. I’ve had an ear infection for the last 5 weeks. Not a big thing, but not good and perhaps it has clouded my view on everything. Too much information, I’m sure. But nevertheless, I do need/would like to finish my 3yr project. Isn’t he?

It’s always the little things that I get caught up in. Often they are most important things. Give me some time to evaluate the solutions posted, in that “Restricting a numeric “range” into an input field” which I posted in the first place, was the question asked. I think the solution/s have been posted.

I’m sure that what is posted will work, but give me some time to resolve this in my own way. A task that becomes harder day by day by day, but I know that I’m the one who has to solve and agree with it (ie. agree in my dumb way) - no disrespect intended to anyone.

If I fail, I can assure you “I” will be the one to blame, If I get my sh*t together, then that would be good and preferable - to me.

You are afraid of being finished. I get that, too. From your screenshots the app looks like version 2 or 3 and not version 1.

The most important thing you can do is to get your app to users. Is the feature you are discussing here important?

Fix some remaining - important - bugs and find some beta testers.