Topic: Select - search box - issue with saving while editing data
                  
                  rimaster
                  free
                  asked 5 years ago
                
Hello
I'm using MDB for my projects on Django. I am using in my forms Select field with a search box. 
It working well when I try to add new record but problem is when I try to edit exist record. The forms look fine and I can see all the data in the fields.
 
 

If I only try to change Department field... is OK and forms i saved. If I try to chanege other fields (without Department) I cant save it. 
Field Department is required. There is a code of Department field:
<div class="form-row mb-3 md-form">
     <select name="depart" class="mdb-select md-form" id="id_depart" required  searchable="Search here..">
          <option value="{{ select.depart }}" selected>{{ select.depart }}</option>
          {% for result in depart %}
          <option value="{{ result.id }}">{{ result.depart }}</option>
          {% endfor %}
     </select>
     <label class="mdb-main-label">Department</label>
 </div>
As you can see there is some data in this field but is problem with saved this form when Department is not changed. In logs looks like this field is empty.
<tr><th><label for="id_dzial">Dzial:</label></th><td><select name="dzial" required id="id_dzial">
  <option value="">---------</option>
  <option value="1">Production</option>
  <option value="2">IT</option>
  <option value="3" selected>Quality</option>
</select></td></tr>
Question: 
Why is the Department field empty despite the value? (---------)
Is there any way to save the field without changing its value?
Thank you for any suggestions.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- ForumUser: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.19.1
- Device: PC
- Browser: Chrome
- OS: Windows 10
- Provided sample code: No
- Provided link: Yes
Grzegorz Bujański free commented 5 years ago
Hi. Can you show how you get the select value? What selector do you use?
rimaster free commented 5 years ago
I'm sorry, my big bad. Now when you ask me about value I found my mistake... I have value="{{ select.depart }}" but should be value="{{ select.id }}"
Thanks and please close this topic