[Seaside] Two part input.

Richard Durr richard.durr at googlemail.com
Wed Feb 10 10:47:40 UTC 2010


Thanks. :) I did it this way in the end:

WACallback subclass: #WATwoToOneCallback
	instanceVariableNames: 'first second block'

WATwoToOneCallback >> fire
	(self first isNil not and: [self second isNil not])
		ifTrue: [ self block value: self first value: self second ].

WATwoToOneCallback >> firstCallback
	^ [ :value | self first: value. self fire.]

WATwoToOneCallback >> secondCallback
	^ [ :value | self second: value. self fire.]


MyComponent >> renderInputOn: html
	| callback |

	callback := WATwoToOneCallback new.
	callback block: [:first :second | second ifNotEmpty: [ self take:
second] ifEmpty: [self take: first] ].
	html select
		addAll: self predefinedOptions;
		callback: callback firstCallback;
		selected: ((self predefinedOptions includes: self string) ifTrue:
[self string] ifFalse: [nil]).
	
	html textInput
		callback: callback secondCallback;
		value: ((self predefinedOptions includes: self string) ifTrue: ['']
ifFalse: [self string]).



On Mon, Feb 8, 2010 at 8:54 PM, Lukas Renggli <renggli at gmail.com> wrote:
>> renderInputOn: html
>>        html select
>>                id: self labelId , 'predefinedOptions';
>>                addAll: self predefinedOptions;
>>                callback: [:v | self take: v ];
>>                selected: ((self predefinedOptions includes: self string) ifTrue:
>> [self string] ifFalse: [nil]).
>>        html textInput
>>                callback: [:v | self take: v ];
>>                id: self labelId;
>>                value: ((self predefinedOptions includes: self string) ifTrue: ['']
>> ifFalse: [self string]).
>>
>> take: anObject
>>        anObject isEmpty ifFalse: [self string: anObject ]
>>
>>
>> predefinedOptions
>>        ^ self description propertyAt: #predefinedOptions ifAbsent:[Array new.]
>>
>> That works, but is very unelegant, since it relies of the order of
>> inputs, for example. Anyone a better Idea how to update using two
>> callbacks at once? ^^
>
> Earlier versions on Seaside had the possibility to add a special menu
> item to the select list that popped up an input box asking the user
> for a new value. Then the Javascript code modified the form so that it
> would display and submit the custom value correctly.
>
> The infrastructure is still in the Magritte model, see #beExtensible
> and #isExtensible on MASingleOptionDescription. It is not anymore in
> Seaside and Magritte-Seaside though, but I guess you could dig it out
> again if needed.
>
> Lukas
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>


More information about the seaside mailing list