What I mean by 'you are mixing your view with your controller' is that you 
are using your controller to build HTML that will be used as-is. You should 
never create HTML in your controllers, leave that to the views. The whole 
point of MVC is that each part has a very specific purpose. Don't create 
your models in your controllers or views, don't create html in your models 
or controllers, and don't put logic in models and views.

https://www.youtube.com/watch?v=8FWdQVNeTlI


On Tuesday, January 27, 2015 at 10:15:50 AM UTC-7, Derek wrote:
>
> Well, where do I start? It looks like you are a victim of copy and paste 
> coding. Delete your two functions and start over again.
>
> That said, you are mixing your view with your controller, please don't do 
> that. I would suggest you use this web2pyslice as a starting point. (yes, I 
> wrote it)
>
> http://www.web2pyslices.com/slice/show/1724/cascading-dropdowns-simplified
>
>
>
>
> On Monday, January 26, 2015 at 1:28:20 PM UTC-7, Omi Chiba wrote:
>>
>> I have a three dropdown and the value will be dynamically changed using 
>> ajax. It's working fine but something is wrong. In second dropdown 
>> (id="lead_name"), I specify jQuery('#model_name') but it's 
>> actually jQuery('#leadl_name') but then when the value for the second drop 
>> changed, the value disappear from the second and third. When I keep the 
>> current way (which is wrong name) it's working as expected.... Do you guys 
>> know what's wrong?
>>
>> This is my view
>>
>> <form enctype="multipart/form-data" action="{{URL()}}" method="post">
>>                 <tr>
>>                 <td><select name='model_name' onchange="jQuery(
>> '#model_name').empty(); 
>>                     ajax('lead_ajax', ['model_name'], 'lead_name');">
>>                     {{for model in models:}}
>>                         <option value="{{=model.Name}}" 
>>                         {{=" selected='selected'" if str(model.Name)=
>> =request.vars.model_name else ""}}>
>>                         {{=model.Name}}
>>                         </option>
>>                     {{pass}}
>>                 </select></td>
>>                 <td><select id='lead_name' name='lead_name' onchange="
>> jQuery('#model_name').empty(); 
>>                     ajax('block_ajax', ['lead_name'], 'block_name');">
>>                     {{for lead in leads:}}
>>                         <option value="{{=lead.Name}}" 
>>                         {{=" selected='selected'" if str(lead.Name)=
>> =request.vars.lead_name else ""}}>
>>                         {{=lead.Name}}
>>                         </option>
>>                     {{pass}}
>>                 </select></td>
>>                  <td><select id='block_name' name='block_name'>
>>                     {{for block in blocks:}}
>>                         <option value="{{=block.Name}}" 
>>                         {{=" selected='selected'" if str(block.Name)=
>> =request.vars.block_name else ""}}>
>>                         {{=block.Name}}
>>                         </option>
>>                     {{pass}}
>>                 </select></td>
>>                     <td></td>
>>                     <td></td>
>>                 <td><input type="submit" value='Submit'></td>
>>                 </tr>
>>             </form>
>>
>> My controller
>>
>> def index():
>>     response.title='KR Quick Delivery Service'
>>     
>>     if request.vars.model_name: 
>>         lists = db((db.KR_Product.Model==request.vars.model_name) & (db.
>> KR_Product.Lead==request.vars.lead_name) & (db.KR_Product.Block==request.
>> vars.block_name)).select(db.KR_Product.ALL)
>>     else:
>>         lists=''
>>     models = db().select(db.KR_Model.ALL)
>>     leads = db(db.KR_Lead.ModelName == '20').select(db.KR_Lead.ALL)
>>     blocks = db(db.KR_Block.LeadName == '01').select(db.KR_Block.ALL)
>>         
>>     return dict(lists=lists,models=models,leads=leads,blocks=blocks)
>>     
>> def lead_ajax():
>>     leads = db(db.KR_Lead.ModelName==request.vars.model_name).select(db.
>> KR_Lead.ALL)
>>     result = ''
>>     for lead in leads:
>>         result += "<option value='" + lead.Name + "'>" + lead.Name + 
>> "</option>"  
>>     return XML(result)
>>     
>> def block_ajax():
>>     blocks = db(db.KR_Block.LeadName==request.vars.lead_name).select(db.
>> KR_Block.ALL)
>>     result = ''
>>     for block in blocks:
>>         result += "<option value='" + block.Name + "'>" + block.Name + 
>> "</option>"  
>>     return XML(result)
>>
>>
>>
>>

-- 
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