Scrolling field Behavior and Maximum Editable Row

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
skywalker
Posts: 3
Joined: Thu Jul 26, 2012 8:55 am

Scrolling field Behavior and Maximum Editable Row

Post by skywalker » Thu Jul 26, 2012 9:20 am

Hello,
I have a fairly simple program I am working on and I'm trying to nail down the best object type and parameters for a data entry table.
I want the user to be able to enter a series of pairs but limit them to 25
For example
a 1
b 2
c 3
...
y 25

This is basically a 2 column, 25 row table, no headers are necessary.
I am currently using a Scrolling field with Maximum Editable Column set to 2. I have Basic Table Object and Cell Editing Selected.
I have two issues:
The first is that when the focus is in the 2nd column, the column shifts left hiding the data in column 1 and revealing a blank column 3.
This is messy even though the user cannot click in column 3. How can I lock this so it won't shift?
The second issue is that I don't want the user to be able to enter more than 25 rows. Simply clicking on blank lines seems to add tabs to the content.

I'd like for tab to be able to be used to move from column 1 to column 2 and then down a row, like is working with the scrolling field. I am hoping the column shifting can be sorted with some parameters. I think the row problem might be able to be sorted by handling keyup or mouseup and testing for the current line, so as to prevent it from ever going beyond line 25.

Any advice would be most appreciated.

-Gopala Walker

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10321
Joined: Wed May 06, 2009 2:28 pm

Re: Scrolling field Behavior and Maximum Editable Row

Post by dunbarx » Fri Jul 27, 2012 7:43 pm

Hi.

This is simple and straightforward if you had two separate fields. But I am not an expert with either table fields or datagrids to the extent that I can trap either a "tabKey" or "RawKeyUp" message in either of those two objects. This even though the message watcher shows "rawKeyUp" as being sent (somewhere).

You can do what you need from a dialog, the target cell derived from a datagrid in a few ways:

Code: Select all

  put the dgHilitedLines of grp "yourDG" into tLine 
   put the dgDataOfLine[tLine] of grp "yourDG" into tData
   put the dgColumn of of the target into tColumn
So either let me know if you are willing to do this with two side by side fields, or via a dialog box in a DG, or wait for someone else to come up with a way to trap the more basic messages. I would be interested to see this.

Craig Newman

skywalker
Posts: 3
Joined: Thu Jul 26, 2012 8:55 am

Re: Scrolling field Behavior and Maximum Editable Row

Post by skywalker » Sat Jul 28, 2012 2:31 am

Thanks for your response Craig,

I am very happy to have two side by side fields, I have been trialing this as an alternative and it does solve the column shifting problem. I am sure the power and flexibility of datagrids will come in handy on another project, but if I can solve this in a simpler fashion it would be good.

I am still curious what the best way to limit entry to 25 rows would be. If you have any suggestions, I would be happy to hear them.

I have not yet tried to trap tabkey or returnkey to switch between fields. I have an idea how to begin but I have had a little difficulty discovering which function will tell me the current row I am focussed in, and if I can jump to the same row of the next field, or the next row of the previous field.

-Gopala Walker

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10321
Joined: Wed May 06, 2009 2:28 pm

Re: Scrolling field Behavior and Maximum Editable Row

Post by dunbarx » Sun Jul 29, 2012 5:33 am

I made two fields, set side by side, named "F1" and "F2".

In field "F1" I placed this:

Code: Select all

on tabKey
   if the number of lines of me <= 25 then
      put word 2 of the selectedLine into tLine
      put return after fld "f2"
      select line tLine of fld "f2"
   else select empty
end tabKey

on keyDown
   if word 2 of the selectedLine  <= 25 then
      pass keydown
   end if
end keyDown

on returnInField
end returnInField
and in field 2 I placed:

Code: Select all

on tabKey
   if the number of lines of me < 25 then
      put word 2 of the selectedLine into tLine
      put return after fld "f1"
      select line tLine + 1 of fld "f1"
  else select empty
end tabKey

on keyDown
   if word 2 of the selectedLine  <= 25 then
      pass keydown
   end if
end keyDown

on returnInField
end returnInField
A great deal of effort is used to overcome the fact that one cannot, in a text field, select a line below the number of lines in that field. In other words, in an empty field, you cannot select line 7, say, and in a field with ten lines, you cannot select line 20. It is the way these things work. You have to pad lines in order to do this, hence the returns.

There is no issue with clicking any line to select it, it just doesn't work with the "select" command. I never liked this.

Anyway, I feel this is somehow inelegant, but it works. There may be issues with how users go back to edit already entered text, but this should get you started. You need to start in fld "F1". I did not prevent you from starting in "f2", where if you do, all goes awry. You should add this.

To others, anyone else hate the fact that you cannot use the "select" command to access the virgin lines in a field?

Craig Newman

skywalker
Posts: 3
Joined: Thu Jul 26, 2012 8:55 am

Re: Scrolling field Behavior and Maximum Editable Row

Post by skywalker » Sun Jul 29, 2012 8:04 am

Thanks for giving me a start in the right direction.
I was having lots of trouble trapping any keystrokes in the scrolling field until I tried changing a few field parameters.
I am not 100% certain, but I believe that Basic Table Object needs to be OFF to properly trap the tabkey and returnkey.
Once I had my fields setup properly then the code kindly provided by Craig worked great.
I want the user to be able to edit later, and this doesn't work well once the fields are full, but I hope to make some additions to add that functionality.
I really appreciate the help, thanks!!

-Gopala Walker

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10321
Joined: Wed May 06, 2009 2:28 pm

Re: Scrolling field Behavior and Maximum Editable Row

Post by dunbarx » Sun Jul 29, 2012 5:59 pm

Glad to help.

What issues are you running into when the fields are full? I had none. You just select any word and type away.

I do see that when editing in the interior of field "F2", tabbing does not move you to the next line in "F1". If this is needed, I hope you can fix that.

Delete was not handled. This will break the relationship between lines. You need to fix that. Also, what about line wrap?

You also need to sync the scroll of the two fields. Are you OK with that?

Write back with any problems.

Craig Newman

Post Reply