Skip to content

Commit

Permalink
Add multiselect type
Browse files Browse the repository at this point in the history
  • Loading branch information
maricaantonacci committed May 17, 2022
1 parent e4a871a commit a9012e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/deployments/templates/input_types.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
{% include 'inputs/dependent_select.html' %}
<!-- end select type -->

{% elif value.type == "multiselect" %}
<select class="js-example-basic-multiple form-control" id="{{key}}" name="{{key}}" multiple="multiple" {{mode}}>
{% for opt in value.options | python_eval %}
<option value="{{opt}}">{{opt}}</option>
{% endfor %}
</select>

<!-- radio type -->
{% elif value.type == "radio" %}
{% for constraint in value.constraints %}
Expand Down Expand Up @@ -226,6 +233,12 @@ <h5 class="modal-title">Storage encryption alert</h5>

});

$(document).ready(function() {
$('.js-example-basic-multiple').select2({
width: '100%' // https://github.com/select2/select2/issues/4220
});
});

</script>


1 change: 1 addition & 0 deletions app/home/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
app.jinja_env.filters['tojson_pretty'] = utils.to_pretty_json
app.jinja_env.filters['extract_netinterface_ips'] = utils.extract_netinterface_ips
app.jinja_env.filters['intersect'] = utils.intersect
app.jinja_env.filters['python_eval'] = utils.python_eval

toscaInfo = tosca.tosca_info

Expand Down
8 changes: 8 additions & 0 deletions app/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def to_pretty_json(value):
indent=4, separators=(',', ': '))


def python_eval(obj):
if isinstance(obj, str):
try:
return eval(obj)
except Exception as e:
app.logger.warn("Error calling python_eval(): {}".format(e))
return obj


def gencolors(hue, n):
rand_color = randomcolor.RandomColor(42)
Expand Down

0 comments on commit a9012e1

Please sign in to comment.