The first of a series of coding vignettes in Seaside.
Context: a web app with a form containing multiple input fields. Instead of waiting to submit the form, I want the page to update another element every time an input is changed. In this example, a total field. Solution was used for a simple MoneyCounter application:
MoneyCounter>>renderContentOn: html html form id: 'f'; with: [
html table: [
html tableRow:
[html tableData: [html text: 'pennies'];
tableData:
[html textInput
id: 'pennies';
"on: #pennies of: self;"
callback: [:value | self pennies: value];
onChange: (html updater
id: 'total';
triggerFormElement: 'pennies';
callback: [ :r | self renderTotalOn: r])
] ]
etc.
html tableRow:
[html tableData: [html text: 'TOTAL'; space];
tableData: [html span id: 'total' ; with: self total]]]]
MoneyCounter>>renderTotalOn: html
html render: self total
MoneyCounter>>pennies: value
pennies := value
MoneyCounter>>total
^((pennies asInteger * 0.01) + etc. )
Continue reading Updater examples with Scriptalicious & Seaside