I am a little confused. I dont think I am using tw2.core.Page. AdminPage is 
just another class in the same file that fills the left_sidebar with a 
couple links, like:

class AdminPage(ATDbPage):
    left_sidebar = [
        LinkField(
        ...

and nothing else.

self.widget does the following:

def widget(self,w,kw={}):
        if kw.get('export'):
            return w.export_data(request)
        else:    
            w = w.request(request)
            return dict(w=w,kw=kw,page=self.page)

I have seen the example you are linking, but that does not help. I am able 
to prefill any value with a pre-defined value already. The problem is, that 
I want to prefill it with a value taken from kw (from the URL). In fact, I 
need it to complain if a certain value ('customer_id') is NOT passed in the 
URL.

Anyone got any ideas?

On Wednesday, July 24, 2013 3:12:57 PM UTC-4, Alessandro Molina wrote:
>
> Well, usually when TW2 is used with TG you don't use tw2.core.Page, as the 
> page is served by TG itself, so I'm not sure if AdminPage is getting 
> between you and the form and causing problems. Nor I know what 
> self.widget() does, so I don't know how the values are used.
>
> When you use the form directly, pre-filling values is as simple as 
> form.display(value={'form_field':'field-value'}) and you get your fields 
> already filled with the passed values.
> You can find a simple example of a form that pre-fills data here: 
> http://turbogears.readthedocs.org/en/tg2.3.0b2/cookbook/TwForms.html#displaying-forms
>
> My suggestion is to try with a simple form like in the linked example and 
> see if it works as expected.
>
>
> On Wed, Jul 24, 2013 at 8:58 PM, Dennis Backhaus <
> [email protected] <javascript:>> wrote:
>
>> custom
>>
>> Here is my controller for the form:
>>
>> class User5amController(AdminBaseController):
>>     @expose('alims.templates.widget')
>>     def index(self, *args, **kw):
>>         log.debug('***%s***' %kw)
>>         return self.widget(UserForm,kw)
>>
>> The debug log is in there to confirm that the attributes I send via the 
>> URL appears in kw (it does)
>>
>> The form is here:
>>
>> class UserForm(AdminPage):
>>     entity = model.User
>>     title = 'User'
>>     class child(FloatForm):
>>         cid=1
>>         css_class = 'floatform'
>>         buttons = [SaveButton(),CancelButton()]
>>         help_msg = 'Enter the information for the new user'
>>         id = HiddenField(validator=twc.IntValidator)
>>         customer_id = TextField(
>>             label="Customer ID",
>>             attrs=dict(disabled=True),
>>             value=cid
>>         )
>>         user_name = TextField(
>>             label="User ID",
>>             validator = twc.Required
>>         )
>>         password = PasswordField(
>>             label="Password",
>>             validator = twc.Required
>>         )
>>
>> Now, basically what I need is to set 'cid' in the form to the value of 
>> 'customer_id' in 'kw' - instead of its current placeholder 'cid=1'.
>>
>> The template is here:
>>
>> <form xmlns:py="http://genshi.edgewall.org/"; class="floatform" 
>> py:attrs="w.attrs">
>>     <div py:if="w.error_msg" class="formerror" py:content="w.error_msg"/>
>>     <div py:if="w.help_msg" class="formhelp"><p 
>> py:content="w.help_msg"/></div>
>>     <div py:replace="w.child.display()"/>
>>     <div py:for="button in w.buttons" class="field" 
>> py:content="button.display()"/>
>> </form>
>>
>> I am assuming here is where I have to do something... I just do not know 
>> what.
>>
>>
>> On Wednesday, July 24, 2013 1:52:03 PM UTC-4, Alessandro Molina wrote:
>>
>>> Hi,
>>> is your form automatically generated by the admin or are you talking 
>>> about a custom made controller and template?
>>>
>>>
>>> On Wed, Jul 24, 2013 at 4:49 PM, Dennis Backhaus <
>>> back...@moxieinformatics.**com> wrote:
>>>
>>>> Sounds like a simple task, *but for some reason this only works for 
>>>> the primary key of the model in my form*.
>>>>
>>>> Example:
>>>>
>>>> /customer - opens an empty form to add a new customer
>>>>
>>>> /customer?customer_id=X - opens a form with the customer information of 
>>>> customer with customer_id = X for edit
>>>>
>>>> /customer?customer_name=Tech - opens an empty form to add a new 
>>>> customer (instead of opening the customer object where customer_name=Tech
>>>>
>>>> Why is this happening? I spent the last two hours on google trying to 
>>>> find answers, but I did not find anything yet. Most answers seem to 
>>>> suggest 
>>>> that it should just simply work. Since it does not, I wonder if this is a 
>>>> TG (TW) issue?
>>>>
>>>>
>>>> In the end I want to get to the point that customers can only be 
>>>> created when customer_name is defined in the URL and the customer_name 
>>>> field is read_only in the form.
>>>>
>>>>
>>>>
>>>> If this is not a TG problem, please direct me to the right answer. 
>>>> Thanks a lot,
>>>>
>>>> Dennis
>>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "TurboGears" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to turbogears+...@**googlegroups.com.
>>>> To post to this group, send email to [email protected].
>>>>
>>>> Visit this group at 
>>>> http://groups.google.com/**group/turbogears<http://groups.google.com/group/turbogears>
>>>> .
>>>> For more options, visit 
>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>> .
>>>>  
>>>>  
>>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "TurboGears" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/turbogears.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to