set focus issue.
-
- Experienced User
- Posts: 140
- Joined: Wed Sep 14, 2016 2:58 pm
- First Name: Mark
- Last Name: Walter
- Company Name: Paragon Consulting Services
- Contact:
set focus issue.
I'm having a problem with set focus in a grid.
My first attempt, I tried to do it with Javascript. Basically, I have a textbox in a grid. I prompt for an item number. When the find button is pressed, I read through the grid looking for a matching item number. When it's found, I want to set focus to that field in the grid, highlight it and allow a user to change the value. I know it's finding it because it is highlighting the field with a javascript select() function. But it's not positioning the cursor in the field.
So, I backed out, and decided to do this in RPG. I put an indicator field on the set focus property for the item in the grid. When the item number is entered, I run a loop to chain to the subfile, when I find the item, I set the indicator on, update the subfile record, bail from the loop and redisplay the control record.
I'm guessing, some other field on the display has the focus set, but I'm not explicitly setting it on anywhere.
Any Ideas?
My first attempt, I tried to do it with Javascript. Basically, I have a textbox in a grid. I prompt for an item number. When the find button is pressed, I read through the grid looking for a matching item number. When it's found, I want to set focus to that field in the grid, highlight it and allow a user to change the value. I know it's finding it because it is highlighting the field with a javascript select() function. But it's not positioning the cursor in the field.
So, I backed out, and decided to do this in RPG. I put an indicator field on the set focus property for the item in the grid. When the item number is entered, I run a loop to chain to the subfile, when I find the item, I set the indicator on, update the subfile record, bail from the loop and redisplay the control record.
I'm guessing, some other field on the display has the focus set, but I'm not explicitly setting it on anywhere.
Any Ideas?
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: set focus issue.
Maybe you're using a grid property that sets the focus, such as the "subfile record number" property?
-
- Experienced User
- Posts: 140
- Joined: Wed Sep 14, 2016 2:58 pm
- First Name: Mark
- Last Name: Walter
- Company Name: Paragon Consulting Services
- Contact:
Re: set focus issue.
Yes, I'm using that property. I didn't realize that it set the focus. If I need to set the position of the scroll bar, and set the focus to a field in the grid, how would I handle that in Javascript. I'd like to keep as much of the processing on the client side as possible as this application will be used in some areas with sketchy wifi.
-
- Experienced User
- Posts: 140
- Joined: Wed Sep 14, 2016 2:58 pm
- First Name: Mark
- Last Name: Walter
- Company Name: Paragon Consulting Services
- Contact:
Re: set focus issue.
Weird thing I found is if I do this, it highlights the correct field in gray. Then, when I click on the scroll bar, It's highlighted in blue and can be changed.
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: set focus issue.
To do it in pure JavaScript, you would use the scrollToRow() function to position the correct row on the screen:
https://docs.profoundlogic.com/x/BADw
Then use the JavaScript focus() method to move the cursor. In case something else is also moving the cursor, sometimes it helps to add a short delay before firing yours, that will cause your focus() to run after whatever the automatic thing is.
For example:
The setTimeout() waits for 200ms (1/5 of a second) before setting focus. Obviously the ids in my example above (mysfl and TextBox8) might not be the same as yours.
https://docs.profoundlogic.com/x/BADw
Then use the JavaScript focus() method to move the cursor. In case something else is also moving the cursor, sometimes it helps to add a short delay before firing yours, that will cause your focus() to run after whatever the automatic thing is.
For example:
Code: Select all
var rowToFocus = 21;
getObj("mysfl").grid.scrollToRow(rowToFocus);
setTimeout(function() { getObj("TextBox8." + rowToFocus).focus(); }, 200);
-
- Experienced User
- Posts: 140
- Joined: Wed Sep 14, 2016 2:58 pm
- First Name: Mark
- Last Name: Walter
- Company Name: Paragon Consulting Services
- Contact:
Re: set focus issue.
Well, it's about half working. The cursor isn't set till I click on the vertical scroll bar. This is my code:
I can see the count turning gray and being selected. It doesn't turn blue with the cursor there till I click on the scroll bar.
Code: Select all
function findRow(itemNumber) {
var myGrid = getObj("Grid1");
var recordCount = myGrid.grid.getRecordCount();
var found = "0";
for (var x = 1; x <= recordCount; x++) {
var curItem = myGrid.grid.getDataValue(x, "SFITM#");
if (itemNumber == curItem) {
var count = getObj("txtCount." + x);
//myGrid.grid.setCursorRecordNumber(x);
//applyProperty(count, "set focus", "true");
myGrid.grid.scrollToRow(x);
//applyProperty(count, "widget type", "textbox");
setTimeout (function() {
count.focus();
count.select();
},200);
found = "1"
return found;
}
}
return found;
}
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: set focus issue.
I'm not sure that I understand what you mean by "clicking the scroll bar". What does a scroll bar have to do with focus on a text field? Maybe I'm misunderstanding the whole situation.
I notice that you are calling select(), and this is working -- but, its after setting the focus. Is it possible that the select() is taking the focus away? or some other action is happening after the focus() that's taking the focus away? It'd be helpful to know what, specifically, triggers this JavaScript to be called... which event on what type of widget, etc?
Also, you didn't mention anything about mobile apps -- but, just in case it applies, its worth noting -- a lot of the time mobile devices (iOS, Android, etc) will block the ability to programmatically receive focus. I think they do this because setting focus causes the touch keyboard to pop-up on the mobile display, which covers a lot of the display and can make the page 'ugly', so under certain circumstance, it blocks it.... if this is a mobile app, you'll want to read up on when you can or can't set focus.
I notice that you are calling select(), and this is working -- but, its after setting the focus. Is it possible that the select() is taking the focus away? or some other action is happening after the focus() that's taking the focus away? It'd be helpful to know what, specifically, triggers this JavaScript to be called... which event on what type of widget, etc?
Also, you didn't mention anything about mobile apps -- but, just in case it applies, its worth noting -- a lot of the time mobile devices (iOS, Android, etc) will block the ability to programmatically receive focus. I think they do this because setting focus causes the touch keyboard to pop-up on the mobile display, which covers a lot of the display and can make the page 'ugly', so under certain circumstance, it blocks it.... if this is a mobile app, you'll want to read up on when you can or can't set focus.
-
- Experienced User
- Posts: 140
- Joined: Wed Sep 14, 2016 2:58 pm
- First Name: Mark
- Last Name: Walter
- Company Name: Paragon Consulting Services
- Contact:
Re: set focus issue.
First Scott, thanks for the help.
This is running in Atrium.
When I run the code, it highlights the correct field, in the correct row in gray. It's like the screen isn't active. If I can't, say type a number into the highlighted field. But, If I click on the vertical scroll bar, the gray field turns blue and I can type into the field.
If there is a way I can paste a screen shot into here, that'd be great.
Thanks.
This is running in Atrium.
When I run the code, it highlights the correct field, in the correct row in gray. It's like the screen isn't active. If I can't, say type a number into the highlighted field. But, If I click on the vertical scroll bar, the gray field turns blue and I can type into the field.
If there is a way I can paste a screen shot into here, that'd be great.
Thanks.
-
- Experienced User
- Posts: 140
- Joined: Wed Sep 14, 2016 2:58 pm
- First Name: Mark
- Last Name: Walter
- Company Name: Paragon Consulting Services
- Contact:
Re: set focus issue.
I've done a recording of what's happening however this system won't allow me to drop it in here. It's an MKV file generated by OBS. Is there a way I can get that to you?
-
- Experienced User
- Posts: 140
- Joined: Wed Sep 14, 2016 2:58 pm
- First Name: Mark
- Last Name: Walter
- Company Name: Paragon Consulting Services
- Contact:
Re: set focus issue.
Ok, I zipped it if you want to take a look.
- Attachments
-
- 2021-04-23 10-34-26.zip
- (4.06 MiB) Downloaded 790 times
Who is online
Users browsing this forum: No registered users and 2 guests