dependent magritte descriptions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

dependent magritte descriptions

Peter Uhnák
Hi,

I'm trying to get dependent magritte descriptions, but it seems like this is not something that can be done in the descriptions:

Imagine a class Contact with "city" and "country" descriptions.
I would like to populate the city description based on the currently selected country

~~~~~~~~~~~~~~~~~~~~~~
descriptionCountry
<magritteDescription>
^ MASingleOptionDescription new
accessor: #country;
label: 'Country';
options: self countries;
yourself

descriptionCity
<magritteDescription>
^ MASingleOptionDescription new
accessor: #city;
label: 'City';
options: (self citiesInCountry: self country);
yourself
~~~~~~~~~~~~~~~~~~~~~~

The problem with this approach is that both descriptions are in the same form, so I need to update the cities list even before the country is saved back into the object.

Is this possible in magritte?

Thanks,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: dependent magritte descriptions

Andreas Brodbeck-3
Am 06.12.17 um 11:34 schrieb Peter Uhnák:

> Hi,
>
> I'm trying to get dependent magritte descriptions, but it seems like this
> is not something that can be done in the descriptions:
>
> Imagine a class Contact with "city" and "country" descriptions.
> I would like to populate the city description based on the currently
> selected country
>
> ~~~~~~~~~~~~~~~~~~~~~~
> descriptionCountry
> <magritteDescription>
> ^ MASingleOptionDescription new
> accessor: #country;
> label: 'Country';
> options: self countries;
> yourself
>
> descriptionCity
> <magritteDescription>
> ^ MASingleOptionDescription new
> accessor: #city;
> label: 'City';
> options: (self citiesInCountry: self country);
> yourself
> ~~~~~~~~~~~~~~~~~~~~~~
>
> The problem with this approach is that both descriptions are in the same
> form, so I need to update the cities list even before the country is saved
> back into the object.
>
> Is this possible in magritte?
I had the same wish and came up with the following solution:

--- It will calculate the options with a block instead of an already
given collection.

--- It will recalculate (aka "not cache") the options if you hit the
"Save" button on the magritte form.

--- It will NOT recalculate the options on the fly when the other
dropdown box has been selected. This probably could be done with some
ajax stuff or a forced HTTP form send.

--- I use my own subclasses for magritte options, for example:

MASingleOptionDescription subclass: #ALMaSingleModelOptionDescription
        uses: TALMagritteOptionDescription
        instanceVariableNames: ''
        classVariableNames: ''
        package: 'Albus-Magritte'

--- See attached fileout of the Trait TALMagritteOptionDescription.

--- You can then describe an option as follows:

descriptionYourAttribute
        <magritteDescription>
        ^ALMaSingleModelOptionDescription new
                accessor: #yourAccessor;
                optionsBlock: ["stuff to calculate your collection"];
                label: 'Your label';
                yourself




Cheers, Andreas


--
Andreas Brodbeck
www.mindclue.ch

TALMagritteOptionDescription.st (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: dependent magritte descriptions

Peter Uhnák
> --- It will NOT recalculate the options on the fly when the other
> dropdown box has been selected. This probably could be done with some
> ajax stuff or a forced HTTP form send.

This is precisely what I need.
Btw I am using in Pharo (so no web).

For now I switched to hand-written spec Form instead of using magritte...

Peter

On Wed, Dec 6, 2017 at 1:58 PM, Andreas Brodbeck <[hidden email]> wrote:
Am 06.12.17 um 11:34 schrieb Peter Uhnák:
> Hi,
>
> I'm trying to get dependent magritte descriptions, but it seems like this
> is not something that can be done in the descriptions:
>
> Imagine a class Contact with "city" and "country" descriptions.
> I would like to populate the city description based on the currently
> selected country
>
> ~~~~~~~~~~~~~~~~~~~~~~
> descriptionCountry
> <magritteDescription>
> ^ MASingleOptionDescription new
> accessor: #country;
> label: 'Country';
> options: self countries;
> yourself
>
> descriptionCity
> <magritteDescription>
> ^ MASingleOptionDescription new
> accessor: #city;
> label: 'City';
> options: (self citiesInCountry: self country);
> yourself
> ~~~~~~~~~~~~~~~~~~~~~~
>
> The problem with this approach is that both descriptions are in the same
> form, so I need to update the cities list even before the country is saved
> back into the object.
>
> Is this possible in magritte?

I had the same wish and came up with the following solution:

--- It will calculate the options with a block instead of an already
given collection.

--- It will recalculate (aka "not cache") the options if you hit the
"Save" button on the magritte form.

--- It will NOT recalculate the options on the fly when the other
dropdown box has been selected. This probably could be done with some
ajax stuff or a forced HTTP form send.

--- I use my own subclasses for magritte options, for example:

MASingleOptionDescription subclass: #ALMaSingleModelOptionDescription
        uses: TALMagritteOptionDescription
        instanceVariableNames: ''
        classVariableNames: ''
        package: 'Albus-Magritte'

--- See attached fileout of the Trait TALMagritteOptionDescription.

--- You can then describe an option as follows:

descriptionYourAttribute
        <magritteDescription>
        ^ALMaSingleModelOptionDescription new
                accessor: #yourAccessor;
                optionsBlock: ["stuff to calculate your collection"];
                label: 'Your label';
                yourself




Cheers, Andreas


--
Andreas Brodbeck
www.mindclue.ch