Hi Anthony,

Sorry I was on another issue, took me away for 2 weeks from below matter. 
Actually i have no issue using SQLFORM, SQLFORM.factory, now I tried custom 
widget, it works well with dropdown box for customer field. The real goal 
is.... I have a field "total" in the quotation, its value depends on the 
sum of all individual items, user should not modify it manually, but I want 
my javascript to update it when user changes the discount on 
edit_quote.html page. So i defined this "total" field with writable=False, 
but I couldn't retrieve the value using jQuery('#quotation_total').val(), 
then I used Firefox Inspector to find out what HTML element it used, then i 
used parseFloat(jQuery('#invoice_total__row').find(".col-sm-9").text()) to 
retrieve the value, then my javascript replaced the value in the form in 
the view, now I hit submit button, this 'total' field value doesn't get 
sent to the server. I did many try and error, it seems writable=True make a 
field disable instead of readonly. This is the whole reason why i used FORM 
and INPUT to construct everything from scratch (actually quite painful), so 
when I defined INPUT(.... _readonly='True'), i could retrieve the value 
using  jQuery('#quotation_total').val() and update it, submit the form also 
sent the total value to the callback function.

When i tried custom widget, the behavior was the same that submitting a 
form didn't sent the non-writable field to server, I need some SERIOUS 
HELP. Is there any way I can make the writable=False field readonly?

Hi Peter, thanks for taking time out to share your the SQLFORM.factory() 
insight, there is no waste of time at all.

On Monday, June 26, 2017 at 10:00:15 PM UTC+8, Anthony wrote:
>
> You do not need to use FORM() and INPUT() helpers just because you need to 
> construct some custom markup for the form. Instead, use SQLFORM as usual 
> and use the form.custom.widget widgets it generates to compose your form, 
> as described here: 
> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Custom-forms.
>  
> You can use those widgets either in the view within custom HTML (as shown 
> in the book), or inside the FORM() helper if you really prefer that method.
>
> You can also generate just the SELECT widget as follows:
>
> SQLFORM.widgets.options.widget(db.quotation.customer, quote_row.customer)
>
> Anthony
>
> On Thursday, June 22, 2017 at 6:34:54 AM UTC-4, Rudy wrote:
>>
>> Hi there,
>>
>> Due to the javascript reason, i need to create a form using FORM and 
>> INPUT helper. I wonder how I can create a form using these helpers with 
>> field displaying a dropdown list for selection (of customer from quotation 
>> form)? Below is a simplified version, currently i created autocomplete to 
>> display a list of customer names matched the input text while user is 
>> typing. Thanks in advance!
>>
>> db.define_table('customer',
>>                 Field('customer_name', requires=[IS_NOT_EMPTY()]),
>>                 format='%(customer_name)s')
>> db.define_table('quotation',
>>                 Field('customer', 'reference customer'),
>>                 Field('project_name', requires=IS_NOT_EMPTY()),
>>                 Field('total', 'double', default=0),
>>                 auth.signature)
>>
>> quote_row = db.quotation(id)
>> quotation_form = FORM(
>>                 'Quotation id:', INPUT(_type='number', _name='id', _value=
>> quote_row.id, _id='quotation_id', _readonly='True', 
>> requires=IS_NOT_EMPTY()),BR(),
>>
>>                 #'Customer Name:', INPUT(_type='number', 
>> _name='customer', _value=quote_row.customer, _id='quotation_customer', 
>> requires=IS_IN_DB(db, 'customer.id', '%(customer_name)s')),BR(), 
>>  DIV(_style="position: absolute;", _id="suggestions", 
>> _class="suggestions"), BR(),
>>                 'Customer Name:', INPUT(_type='text', _name='customer', 
>> _value=db.customer(quote_row.customer).customer_name, 
>> _id='quotation_customer', requires=IS_IN_DB(db, 'customer.id', 
>> '%(customer_name)s')),BR(), DIV(_style="position: absolute;", 
>> _id="suggestions", _class="suggestions"), BR(),
>>
>>                 'Project Name:', INPUT(_type='text', 
>> _name='project_name', _value=quote_row.project_name, 
>> _id='quotation_project_name'),BR(),
>>                 'Total:', INPUT(_type='number', _step='0.01', 
>> _name='total', _value=quote_row.total, _id='quotation_total', 
>> _readonly='True'),BR(),
>>                 INPUT(_type='submit'))
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to