WEBUI autocomplete means validation, too

This commit is contained in:
boyska 2017-01-03 21:16:52 +01:00
parent af9464c966
commit a70033e167
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9

View file

@ -2,6 +2,36 @@
{% import "bootstrap/wtf.html" as wtf %} {% import "bootstrap/wtf.html" as wtf %}
{% block title %}Larigira - DB add audio "{{kind}}" {%endblock%} {% block title %}Larigira - DB add audio "{{kind}}" {%endblock%}
{% block scripts %}
{{super()}}
<script type="text/javascript">
function check_suggestion(el) {
val = $(el).val();
datalist = $(document.getElementById($(el).attr('list')));
values = $('option', datalist).map(function(i, x) { return $(x).attr('value'); });
if($.inArray(val, values) != -1) {
$(el).closest('div.form-group').removeClass('has-warning has-feedback');
$('.not-in-datalist', $(el).parent()).remove()
} else {
$(el).closest('div.form-group').addClass('has-warning has-feedback');
if($('.not-in-datalist', $(el).parent()).length === 0) {
$(el).parent().append($('<span class="not-in-datalist glyphicon glyphicon-warning-sign form-control-feedback"/>'))
$(el).parent().append($('<span/>')
.addClass('help-block not-in-datalist')
.text('Warning: larigira is not sure this path is correct'));
}
}
}
$(function() {
$('input[list]').each(function(i, el) {
check_suggestion(el);
})
});
$('form').on('change keyup', 'input[list]', function(evt) {
check_suggestion(evt.target);
});
</script>
{%endblock scripts %}
{% block content %} {% block content %}
{% if form.errors %} {% if form.errors %}