Making certain BeanEditForm fields 'read only'

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Making certain BeanEditForm fields 'read only'

Christopher
Hi all,

I'm just wondering whether there is a simple and elegant way of making
certain BeanEditForm fields 'read only' within the controller class,
rather than in the view template?  In certain circumstances I wish to
dynamically prevent users from modifying certain fields (a pretty common
scenario).

It would be nice to inject a field component in the controller, and
simply invoke setReadOnly() to have it display its value within the
BeanEditForm, but grayed out and unable to be altered.  These fields are
all 'Select' type in my case.

The Select component has a 'disabled' parameter, but I suspect a
disabled field would behave quite differently—possibly not even
displaying its value.

Below is an example field taken from the template.

     <p:vesselSelected>
         <div class="form-group">
             <label t:type="label" t:for="vessel"/>
             <select t:type="select" t:id="vessel"
t:value="vesselSelected" t:model="vesselSelectModel"
t:label="message:label.vessel"/>
         </div>
     </p:vesselSelected>

Regards,

Chris.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry.
Reply | Threaded
Open this post in threaded view
|

Re: Making certain BeanEditForm fields 'read only'

Thiago H de Paula Figueiredo
Hello!

I don't think there's a way of doing that that doesn't require changing
BeanEditor (which does the heavy lifting for BeanEditForm) and one at least
one of PropertyModel and PropertyConduit.



On Tue, Aug 18, 2020 at 6:19 AM Christopher Dodunski (Tapestry) <
[hidden email]> wrote:

> Hi all,
>
> I'm just wondering whether there is a simple and elegant way of making
> certain BeanEditForm fields 'read only' within the controller class,
> rather than in the view template?  In certain circumstances I wish to
> dynamically prevent users from modifying certain fields (a pretty common
> scenario).
>
> It would be nice to inject a field component in the controller, and
> simply invoke setReadOnly() to have it display its value within the
> BeanEditForm, but grayed out and unable to be altered.  These fields are
> all 'Select' type in my case.
>
> The Select component has a 'disabled' parameter, but I suspect a
> disabled field would behave quite differently—possibly not even
> displaying its value.
>
> Below is an example field taken from the template.
>
>      <p:vesselSelected>
>          <div class="form-group">
>              <label t:type="label" t:for="vessel"/>
>              <select t:type="select" t:id="vessel"
> t:value="vesselSelected" t:model="vesselSelectModel"
> t:label="message:label.vessel"/>
>          </div>
>      </p:vesselSelected>
>
> Regards,
>
> Chris.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
Thiago
Reply | Threaded
Open this post in threaded view
|

Re: Making certain BeanEditForm fields 'read only'

Christopher
In reply to this post by Christopher
Thanks Thiago.

I guess it's something worth considering in the future - updating
BeanEditor and related components to better leverage HTML5 features.

A workaround in my case was to have SelectModelFactory reduce the number
of selectable elements down to one, making selecting something different
impossible.  The fields of interest are synthetic properties added to
the BeanModel, so this workaround was possible.

Regards,

Chris Dodunski.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry.
Reply | Threaded
Open this post in threaded view
|

Re: Making certain BeanEditForm fields 'read only'

Thiago H de Paula Figueiredo
On Wed, Aug 26, 2020 at 7:27 AM Christopher Dodunski (Tapestry) <
[hidden email]> wrote:

> Thanks Thiago.
>

My pleasure to help!


> I guess it's something worth considering in the future - updating
> BeanEditor and related components to better leverage HTML5 features.
>

Which ones, specifically? And Tapestry form field components do handle
disabled="true" correctly as far as I remember, completely ignoring
disabled components when processing the form submission, so I don't think
your workaround described below is needed.

What HTML5 features do you mean?


>
> A workaround in my case was to have SelectModelFactory reduce the number
> of selectable elements down to one, making selecting something different
> impossible.  The fields of interest are synthetic properties added to
> the BeanModel, so this workaround was possible.
>
> Regards,
>
> Chris Dodunski.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
Thiago
Reply | Threaded
Open this post in threaded view
|

Re: Making certain BeanEditForm fields 'read only'

Christopher
In reply to this post by Christopher
Hi Thiago,

A couple of years' ago I extended Tapestry's AbstractField to create a
DateTimeField, as DateField's standard JavaScript calendar looks a
little dated (pardon the pun).  DateTimeField leverages the HTML5
datetime-local input type, and one of its parameters is 'boolean
readOnly'.  I think the wheel-based date picker has a more modern feel,
and is more mobile friendly.

I'm happy to contribute the code for this component if you think it
might make a good form field, an optional alternative to DateField?

My original question was more about exploring the possibility of
manipulating form field components from within the controller class, and
whether this is a good idea or not.  I like to keep the view template as
'dumb' as possible, free of multiple <t:if...> and suchlike.

Although I never tried it, the below may be a better approach than the
one I took.

     <t:select ... t:disabled="disabled" t:readonly="readonly"/>

     public isDisabled() {
         return ...;
     }

     public isReadonly() {
         return ...;
     }

Regards,

Chris.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry.