Jorge Godoy wrote:
> Gary Doades <[EMAIL PROTECTED]> writes:
> 
>> One more question if I may. How to change the attributes of statically 
>> declared form fields at runtime. I need to set some fields to readonly 
>> or change the maxlength of a TextField for example. What's the best way 
>> to do this per request?
> 
> Hmmm...  You can't change some things after you instantiated your widget.  The
> best way that I know that would work is using AJAX to get the values from the
> application and then changing the aspect of the form with your callback.  
> 
> But depending on what you want to change it might be possible by passing a
> dict to your widget on your view.
> 

Ah, I just feel like I'm digging myself a big hole here.

It just seems really messy to have to resort to AJAX and add stuff into 
both controller and view just to toggle some properties on some fields 
at runtime. From the nature of MVC this really ought to be done in the 
controller as it may require complex logic to sort it out.

I can't believe that this is not often needed for most real world 
applications. What do other people do in this situation?

I'll look into what I can do by passing dicts to the template.

In .NET I would have done something like this:

     if (user.viewolnly)
       {
          field1.readonly = true;
          ....
          field10.readonly = true;
          field11.maxlength = 32;
       }

In that system, each valid HTML attribute is exposed as a property on a 
"widget". This makes it so simple to program. This would still not work 
for TG though because of the single instance nature of forms (at least 
in the standard, recommended way of doing things)

It would be very nice if something similar were available in TG or at 
least in ToscaWidgets before TG 2.0 is done.

Thanks again,
Gary.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to