質問

So I want to do something like:

html unorderedList: [
group := html radioGroup.
self employeeNames do: [ :eachEmp | 
                    html listItem: [
                                group radioButton
                                   selected: <set tmpVar = empKey>
                                   callback: [ self <dependent on button pushed> ].            
                         html text: eachEmp ] ] ]   ]

What I would like this to do is generate a list of employees, with radio buttons on each line. Then, depending on the radio button that's selected and which button is pushed, we do some action.

So a visual representation of what I want is something like:


|Post Timecard| --- |Timesheet History| --- |Print Paycheck| --- |Delete|

  • Employee 1 ..... data .... data .... data
  • Employee 2 ..... data .... data .... data
  • Employee 3 ..... data .... data .... data
  • Employee 4 ..... data .... data .... data
  • Employee 5 ..... data .... data .... data

So they could for example, select Employee 3 and then push |Delete| - this would trigger a delete for Employee 3.

I think I can handle what to do for the selected: portion of my code, but I've no clue how to handle the callback? Is there a way to dynamically choose what to call?

役に立ちましたか?

解決

Since you are using a radio group anyway you'll only be able to select a single entry from the list of employees. Now, if you use a form element to wrap the controls, your action anchors could simply trigger a submit of the form:

formName := 'employee-form'.

html form
    name: formName;
    with: [
        html unorderedList: [
            group := html radioGroup.
            self employeeNames do: [ :eachEmp | 
            html listItem: [
                group radioButton
                    selected: nil "<set tmpVar = empKey>";
                    callback: [ :value | self "<dependent on button pushed>" ];  
                    with: eachEmp ] ] ] ].

html anchor
    submitFormNamed: formName;
    callback: [ :value | self handleDelete ]
    with: 'delete'

The callback of the anchor will be evaluated after all of the callbacks of the form elements.

Side note: notice the use of with: to set the anchor and radio button texts. You should almost always use with: as the last message to html.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top