Skip to content

Commit

Permalink
Fix/edit taxon (PnX-SI#561)
Browse files Browse the repository at this point in the history
* Fix : bug lorsqu'un attribut n'a pas de valeur à valeur_attribut

* Style autocomplete + erreur js
  • Loading branch information
amandine-sahl authored Oct 1, 2024
1 parent 2f518fb commit f4dd5cb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion apptax/admin/admin_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def _get_attributes_value(self, taxon_name, theme_attributs_def):
tatt for tatt in taxon_name.attributs if tatt.id_attribut == a.id_attribut
]

if taxon_att:
if taxon_att and attributes_val[a.id_attribut]:
try:
attributes_val[a.id_attribut]["taxon_attr_value"] = eval(
taxon_att[0].valeur_attribut
Expand Down
55 changes: 31 additions & 24 deletions apptax/admin/static/js/taxref_autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
$(document).ready(function () {
let search = document.getElementById("search_value").value;
$(".taxref-autocomplete").select2({
ajax: {
url: function (params) {
if (search !== undefined && params == "") {
params = search;
}
return URL_API_AUTOCOMPLETE + "?search_name=" + params;


$('.jquery-select2').select2();

if (document.getElementById("search_value")) {
let search = document.getElementById("search_value").value;
$(".taxref-autocomplete").select2({
ajax: {
url: function (params) {
if (search !== undefined && params == "") {
params = search;
}
return URL_API_AUTOCOMPLETE + "?search_name=" + params;
},
results: function (data, page) {
var data = $.map(data, function (obj) {
var search_name = obj.search_name.replace("<i>", "");
search_name = search_name.replace("</i>", "");
obj.id = obj.cd_nom;
obj.text = search_name;
return obj;
});
return { results: data };
},
},
results: function (data, page) {
var data = $.map(data, function (obj) {
var search_name = obj.search_name.replace("<i>", "");
search_name = search_name.replace("</i>", "");
obj.id = obj.cd_nom;
obj.text = search_name;
return obj;
});
return { results: data };
},
},
dataType: "json",
delay: 250,
placeholder: "Nom latin, nom vernaculaire, cd_nom",
minimumInputLength: 3,
});
dataType: "json",
delay: 250,
placeholder: "Nom latin, nom vernaculaire, cd_nom",
minimumInputLength: 3,
});

}
});
2 changes: 1 addition & 1 deletion apptax/admin/templates/admin/edit_taxref.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h6>{{theme}}</h6>
rows="3"
>{{attributes_val[attr.id_attribut]['taxon_attr_value']}}</textarea>
{% elif attr.type_widget in ('select', 'multiselect') %}
<select class="form-control" id="{{attr.nom_attribut}}" name="attr.{{attr.id_attribut}}"
<select class="form-control jquery-select2" id="{{attr.nom_attribut}}" name="attr.{{attr.id_attribut}}"
{% if attr.type_widget == 'multiselect' %} multiple {% endif %}
>
<option value="">--</option>
Expand Down

0 comments on commit f4dd5cb

Please sign in to comment.