Seaside checkbox

70 views
Skip to first unread message

David Pennington

unread,
Apr 13, 2024, 7:11:17 AMApr 13
to VAST Community Forum
I asked this question quite some years ago but have forgotten the answer.

I am trying to add checkboxes to my Seaside code. The following code:

showTrainsInStation: html

|sItem|
sItem := true.
html form: [
html table:[
html tableRow: [html tableHeading:  'Trains In Station'].
self trainsInStation doWithIndex:[ : each : i  | 
html tableRow: [
html tableData: each pvNameWithLoco.  
html tableData: (html checkbox
value: (self isSelected: sItem);
callback: [ :value | self selectRow: sItem value: value ]) ]
]]].
! !

Shows as you can see here - http://www.bbbweb.com:8080/PVHome

As you can see, the code doesn’t work. I would like to add a checkbox to the end of each of the entries  in the Trains in Station list.

Can anyone help please?

David

Louis LaBrunda

unread,
Apr 13, 2024, 9:47:32 AMApr 13
to VAST Community Forum
Hi Dave,

I'm not sure what your code it trying to do?  But:

Should this:

html tableData: (html checkbox
value: (self isSelected: sItem);
callback: [ :value | self selectRow: sItem value: value ])

be this:

html tableData: (html checkbox
value: (self isSelected: each);
callback: [ :value | self selectRow: each value: value ])

Note: #each instead of #sItem.

I assume #selectRow: returns a boolean.  It may also help to add: #with: 'Something that Describes what the checkbox is for'.

Note: I have used #value: and #callback:, #on: #symbol of: anObject;, and #onTrue: [what to do when true] onFalse: [what to do when false];.  They all work well and have there place.

Lou

David Pennington

unread,
Apr 13, 2024, 10:12:04 AMApr 13
to VAST Community Forum
OK, so here is it in full. Sorry if I didn't make it clear.

I have a model railway with four locos. There are a maximum of 19 different trains that I can run using these locos.
I have room on my small layout station for a maximum of 2 trains. Once a loco is in use, all the other trains that use that loco drop out of the list of possibles.

So I ask for the first train and accept it. It goes into the TrainsInStation list. I do the same with the next train. I now have two trains in the station. Before I can accept another one, I have to drive one of these two out and back into storage.

I would like to go to the list of trains in station, select a checkbox for the train I am taking back and hit the "clear accepted train" button. 
This should give me a list of checkboxes that are now "true" - and it will be just the one so that I can now reset its "inStation" flag and run the train back out and everything is where it should be.

Currently, when I hit the "clear accepted train" button there is nothing anywhere that tells me the state of these checkboxes. Do I have to name them and find them in the list of items on the page or is there s simpler way of doing this?

Louis LaBrunda

unread,
Apr 13, 2024, 11:58:03 AMApr 13
to VAST Community Forum
Hi Dave,

If you were not working with Smalltalk and Seaside, you probably would expect to get a list of checkboxes via names or ids and their values (I have never used anything but Smalltalk/Seaside, so I'm not sure how to do this or how it works).  With Smalltalk/Seaside I would have an instance variable on the objects in #trainsInStationwith getters/setters that have the same name like #inUse and #inUse:.  The names of the getters/setters must match.  Then use #on:of: where the on: part is the getter/setter name and the of: part is an instance of your object.  On submit, those objects with have the variable set to true for the objects that match the checkbox that is checked.  You can then run the collection for all instances with #inUse (or whatever you call it) true.

If you can't add #inUse to your existing class, you can come up with some other means of storing the returned values of the checkboxes and use #value: to set the checkbox and #callback: to get it but the above is much nicer.  The #value: and #callback: are way is probably better used for things that aren't displayed in a table of rows for each object.

Lou

David Pennington

unread,
Apr 13, 2024, 1:30:07 PMApr 13
to VAST Community Forum
Sorry but I am not sure that I follow this.

Within this class there is an object called trainsInStation that contains a SortedCollection. Each of the (currently) two objects in this list respond to pvInStation which is a boolean and currently set to true for both of them.

I have set up the following code which is obviously wrong as nothing changes.

showTrainsInStation: html

|sItem|
sItem := 'Checkbox'.

html form: [
html table:[
html tableRow: [html tableHeading:  'Trains In Station'].
self trainsInStation doWithIndex:[ : each : i  |
html tableRow: [
html tableData: each pvNameWithLoco.  
html tableData:[html checkbox
on: #pvInStation of: each ]
]]]].

each are elements of the SortedCollection whilst each responds to #pvInStation.
I would expect/hope that #pvInStation would change with the value of the checkbox but no...
I assume that I have got this totally wrong!
David

Louis LaBrunda

unread,
Apr 13, 2024, 2:51:24 PMApr 13
to VAST Community Forum
Hey Dave,

I think the code displays things properly.  I'm guessing that if unchecked, on the next submit, #pvInStation gets set to false but then something else sets it to true again.

Is there a #pvInStation: method?  Does it simply set a boolean variable?  I may not be seeing enough of the big picture and the rest of your code.  That said: do you have two collections of trains?  One with  trainsInStation and one with the rest of the trains.  Could you simplify this to one collection of all trains, with each train having an indicator set to true if the train is in the station?  You could then select (and sort) and create rows for each train in the station.  When displayed, the checkboxes should be checked.  If unchecked, they will be set to "not in the station" and not displayed the next time.

I don't think I understand how you want the buttons and code to flow.

Lou

P.S.  I think my testing broke the current running system.

David Pennington

unread,
Apr 13, 2024, 3:00:25 PMApr 13
to VAST Community Forum
I will have a look but surely, it should be simpler. Yes, you hit a self halt but that just confirmed that nothing had changed.

Louis LaBrunda

unread,
Apr 14, 2024, 9:55:28 AMApr 14
to VAST Community Forum
Well Dave,

I guess simplicity, like beauty, is in the eye of the beholder.  For me, it is simpler to have one collection of object that know if they are in the station.  Does in the station mean they have a locomotive or that they don't?  Anyway, it is easier for the checkboxes to automatically change the state on a submit than to somehow inspect the checkboxes and manually more things from one collection to another.

Lou

P.S.  If you can, please show more code like for: #showTrainsInStation:, #isSelected: and #selectRow:value:.

David Pennington

unread,
Apr 14, 2024, 12:47:28 PMApr 14
to VAST Community Forum
Thanks Lou, as usual, for all your help. However, it seems that, as far as I can see, checkboxes need some backup to work be it Javascript of Ajax. I gave up on all that when I finished my degree in 2017 so I needed to find a simpler way, as you advised. I found a book by Portland State Uni that discussed a contact list. They used an unorderedList along with an anchor. The list showed the name and then added a link to a "remove" action. This i can do standing on my head so, 10 minutes later, I have working system. You can check it out at http://www.bbbweb.com:8080/PVHome which should work now without any self halts, etc. Try it on a phone, which is where I want it. I am now free from my computer and railroad controller  as the controller has a radio link so no wires and the phone is small and handy.

Louis LaBrunda

unread,
Apr 14, 2024, 1:59:40 PMApr 14
to VAST Community Forum
Hi Dave,

Looks good.  Given the way you have things setup, using checkboxes was probably not the best choice.  You can also do what you want with "Remove" buttons with a #callback: which should be simpler than the links.

Lou

David Pennington

unread,
Apr 19, 2024, 3:31:05 PMApr 19
to va-sma...@googlegroups.com
Sounds a good idea. I will do that. Thanks for the help Lou.

-- 
You received this message because you are subscribed to a topic in the Google Groups "VAST Community Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/va-smalltalk/sAwQRnS5bxA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to va-smalltalk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/va-smalltalk/9dc57578-88f7-4881-bd1f-179b69a99fb1n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages