Form elements are reset after #lightbox:

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

Form elements are reset after #lightbox:

ZuLuuuuuu-2
Hello,

In a widget, if I have a form with input elements, after I show a
lightbox via #lightbox: message, the contents of the input elements
are reset. By reset I mean their value becomes empty if I have not set
any value via #value: at the beginning, and if I have set them to some
value at the beginning and modify them when the page is shown it
becomes the initial value after I show a lightbox. How can I avoid
this behaviour?

Here is a simple application you can try:

Lightbox.st
-------------

Iliad.ILApplication subclass: Lightbox [
        Lightbox class >> path [
                ^'lightbox'
        ]

        index [
                <category: 'controllers'>

                ^[:e |
                        e text: 'Write something below:'.
                        e build: MyWidget new]
        ]
]



MyWidget.st
---------------

Iliad.ILWidget subclass: MyWidget [
        contents [
                ^[:e |
                        e form
                                build: [:form |
                                        form input.

                                        form button
                                                text: 'Click Me';
                                                action: [self lightbox: MyWidget new]]]
        ]
]
Reply | Threaded
Open this post in threaded view
|

Re: Form elements are reset after #lightbox:

Nicolas Petton
Le mardi 7 septembre 2010 15:40:45, ZuLuuuuuu a écrit :
> Hello,
>
> In a widget, if I have a form with input elements, after I show a
> lightbox via #lightbox: message, the contents of the input elements
> are reset. By reset I mean their value becomes empty if I have not set
> any value via #value: at the beginning, and if I have set them to some
> value at the beginning and modify them when the page is shown it
> becomes the initial value after I show a lightbox. How can I avoid
> this behaviour?

This is because when you show the lightbox, it adds a delegator to the widget
, so it is marked dirty.

The simplest hack is probably to add an hidden widget which will be
responsible for showing theee lightbox.

hiddenWidget [
         ^hiddenWidget ifNil: [hiddenWidget := self widgetFor: [:e |]]
]

contents [
        ^[:e |
            e build: self hiddenWidget.
            e a action: [self showLightbox: MyWidget new]]
]

showLightbox: aWidget [
        self hiddenWidget lightbox: aWidget
]

In some apps, I even add such a widget in the application directly, then all
lightboxes are displayed through this widget.

Cheers,
Nico

--
Nicolas Petton
http://www.objectfusion.fr
Objectfusion S.A.R.L.
Applications web - Design
Reply | Threaded
Open this post in threaded view
|

Re: Form elements are reset after #lightbox:

ZuLuuuuuu-2
On Sep 8, 3:28 pm, Nicolas Petton <[hidden email]> wrote:
> This is because when you show the lightbox, it adds a delegator to the widget
> , so it is marked dirty.


Hmm, I see...


>
> The simplest hack is probably to add an hidden widget which will be
> responsible for showing theee lightbox.
>


A global dialog widget also came to my mind to simplify my code in
general but for some reason I gave up the idea until I saw the code
piece below:


> hiddenWidget [
>          ^hiddenWidget ifNil: [hiddenWidget := self widgetFor: [:e |]]
> ]


this little, cute #widgetFor: message will be very very useful to me!

Thank you very much...

Canol