Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

What is the correct way to create a search field inside a form and filter out data in a dropdown?

Subscribe

Get notified when there's activity on this post

This question has been flagged
formcontrollerswebsiteodoo9.0
2 Replies
15570 Views
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

Hi guys,

I've been building some pages in the Odoo website but I've ran into an issue where I'm not sure what the best way is to handle it. I've created a new form, which is partially filled up with data from the controller, and in the middle of this form I need a search field with search button to filter a dropdown. The controller:

class project_issue(http.Controller): # Sends user to the creation page for a new ticket @http.route('/support/ticket/submit', type="http", auth="public", website=True) def support_submit_ticket(self, **kw): """Let's public and registered user submit a support ticket""" values = {} for field_name, field_value in kw.items(): values[field_name] = field_value partner_id = None if http.request.env.user.id: partner_id = http.request.env.user.partner_id.id return http.request.render('my_module.support_submit_ticket', {'equipments': http.request.env['product.product'].sudo().search([('equipment_customer_id', '=', partner_id)]), 'name': http.request.env.user.name, 'email': http.request.env.user.email, 'phone': http.request.env.user.phone})

The XML view for the page:

<template id="support_submit_ticket" name="Create new ticket" page="True"> <t t-call="website.layout"> <div id="wrap" class="oe_structure oe_empty"> <section> <div class="container"> <div class="row">

<div class="col-md-12"> <h1 class="text-center">Create new ticket</h1> </div> </div> </div> </section> <div class="form-horizontal mt32"> <form action="/support/ticket/process" method="get" class="form-horizontal mt32" enctype="multipart/form-data"> <!-- subject --> <div name="subject" t-attf-class="form-group #{error and 'subject' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="subject">Subject</label> <div class="col-md-7 col-sm-8"> <input type="text" class="form-control" name="subject" required="True"/> </div> </div> <div t-attf-class="form-group #{error and 'person_name' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="person_name">Name</label> <div class="col-md-7 col-sm-8"> <input type="text" class="form-control" name="person_name" required="True" t-attf-value="#{name or ''}" t-attf-readonly="#{name and 'readonly'}"/>

</div> </div> <div name="email_from_container" t-attf-class="form-group #{error and 'email' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="email">Email</label> <div class="col-md-7 col-sm-8"> <input type="email" class="form-control" name="email" required="True" t-attf-value="#{email or ''}" t-attf-readonly="#{email and 'readonly'}"/> </div> </div>

<!-- Phone number --> <div name="phone_container" t-attf-class="form-group #{error and 'phone' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="phone">Phone</label> <div class="col-md-7 col-sm-8"> <input type="phone" class="form-control" name="phone" required="True" t-attf-value="#{phone or ''}"/> </div> </div> <!-- Ticketing number --> <div name="customer_ticket_number" t-attf-class="form-group #{error and 'customer_ticket_number' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="customer_ticket_number">Customer ticket number</label> <div class="col-md-7 col-sm-8"> <input type="text" class="form-control" name="customer_ticket_number" required="True"/> </div> </div>

<!-- Search option for filtering on equipments. --> <div class="form-group"> <form action="" method="get" class="navbar-search pull-right pagination form-inline"> <label class="col-md-3 col-sm-4 control-label" for="search">Filter equipment</label> <div class="col-md-7 col-sm-8" style="width:50% !important;"> <input type="text" name="search" class="search-query form-control oe_search_box" placeholder="Search..." t-att-value="search"/> <span class="fa fa-remove fa-lg oe_search_clear"></span>

</div> <span class="input-group-btn"> <button type="submit" class="btn btn-default oe_search_button"><i class="fa fa-search"/></button> </span> </form> </div> <!-- Equipment --> <div t-attf-class="form-group #{error and 'equipments' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="equipments">Equipment</label> <div class="col-md-7 col-sm-8"> <select class="form-control" name="equipment"> <t t-foreach="equipments" t-as="equipment"> <option t-attf-value="#{equipment.id}"> <t t-esc="equipment.name"/> <t t-if="equipment.serial_number">- Serial number: <t t-esc="equipment.serial_number"/> </t> </option> </t> </select> </div> </div>

<!-- Urgency --> <div name="priority" t-attf-class="form-group #{error and 'priority' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="priority">Priority</label> <div class="col-md-7 col-sm-8"> <select class="form-control" name="priority"> <option t-att-value="1">1</option> <option t-att-value="2">2</option> <option t-att-value="3">3</option> <option t-att-value="4">4</option> <option t-att-value="5">5</option> </select> </div> </div> <div t-attf-class="form-group #{error and 'description' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="description">Description</label> <div class="col-md-7 col-sm-8"> <textarea class="form-control" name="description" style="min-height: 120px" required="True"></textarea> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-sm-offset-4 col-sm-8 col-md-7"> <button class="btn btn-primary btn-lg">Submit Ticket</button> </div> </div> </form> </div> </div> </t> </template>

The problem is that the search field and the search button need to be in a form but all the other content needs to be in another form. When I don't enwrap all fields in a form to be sent when clicking in the button 'Submit Ticket' I cannot access the data in my controller but I can't nest forms either. So, what is the correct / best way to create a search functionality inside a form that filters out the dropdown?

This dropdown:

<!-- Equipment -->

<div t-attf-class="form-group #{error and 'equipments' in error and 'has-error' or ''}"> <label class="col-md-3 col-sm-4 control-label" for="equipments">Equipment</label> <div class="col-md-7 col-sm-8"> <select class="form-control" name="equipment"> <t t-foreach="equipments" t-as="equipment"> <option t-attf-value="#{equipment.id}"> <t t-esc="equipment.name"/> <t t-if="equipment.serial_number">- Serial number: <t t-esc="equipment.serial_number"/> </t> </option> </t> </select> </div> </div>

I should be able to filter the field equipment when the user fills in something in the searchbar and clicks on search. By doing so the dropdown will be filtered out so that only matches still show op.

So, how should I accomplish this?

Thanks,

Yenthe  

2
Avatar
Discard
Avatar
Jérémy Kersten (jke)
Best Answer

Best way according to me, you should do your search in ajax.

That will avoid re-rendering the form at each search, lost data and co...


Perso, I will use select2 to do it. 

You can take inspiration / a look in forum (tag field) code.

1
Avatar
Discard
Yenthe Van Ginneken (Mainframe Monkey)
Author

Thanks for your reply Jérémy! Good point about the Ajax and the reloading of forms etc. It is indeed better to not reload a page if it isn't needed. I've been giving your idea an attempt but I'm a bit stuck. I see that on the help forum everything is embedded in a form but I already have an open form so how should I handle that? The second thing is that my JS doesn't go off. Could you give me some pointers please? I've posted the needed files on Github for you to view: https://github.com/Yenthe666/Dev/tree/master/aa_cameo_ticketing

Yenthe Van Ginneken (Mainframe Monkey)
Author

Also, I will convert all this knowledge in a new blogpost for the community. :-)

Jérémy Kersten (jke)

Hey yenth, what is the state of this dev ? still need help or it's finish ?

Jérémy Kersten (jke)

See https://github.com/Yenthe666/Dev/pull/11

Yenthe Van Ginneken (Mainframe Monkey)
Author

This is a great answer, thanks a lot Jérémy! Upvoted & accepted.

Avatar
Chetan
Best Answer

I have a similar issue will you please provide the solution.

I want to use ajax in select2/select in the search bar to filter the product according to the search input.











Js code

_onProductButtonC: function(ev) {

var self = this;

//select2 for product select. formatState function to show image

$('#product_list').select2({ formatResult: self.formatState,formatSelection: self.formatState, minimumInputLength: 3 });

$('#product_list').on('change', function (e) {

$('#product_id').val($('#product_list').val());

});

$('.modal_add_requisition_product .select2-container').css({"width": "100%"});

$('.modal_add_requisition_product .select2-container a.select2-choice').css({"height": "50px"});

},



0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to create multi step website forms?
form controllers website v14
Avatar
Avatar
Avatar
2
Feb 24
6422
How to attach image in custom website form
attachment form controllers website
Avatar
Avatar
1
Jun 23
6556
How to get a Many2one contact from controller
form many2one controllers website
Avatar
Avatar
1
Sep 22
3295
Data from website with controller Solved
controllers website
Avatar
Avatar
Avatar
2
Jul 24
4898
website form
form website
Avatar
Avatar
Avatar
2
May 25
10592
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now