You can first set your button to be disabled by adding the disabled attribute. Note, I added an id attribute to your button and the form. There's also a <p>
tag to use as a result/error message but you can customize this.
<form action="" method="post">
<input type="text" class="form-control" id="input" list="colours" name="colours">
<datalist id="colours">
<option value="Red" data-id="1">
<option value="Blue" data-id="2">
<option value="Green" data-id="3">
<option value="Black" data-id="4">
<option value="White" data-id="5">
</datalist>
<button id="myButton" disabled type="submit" class="btn btn-info" name="confirm">Zapisz</button>
</form>
<p id="result"></p>
Then add a listener in javascript to listen to any changes to the input form, and run a validation check by looping the input value over the options. If the validation passes, it sets the disabled attribute to false. If not, it will throw a message in the bottom.
Here is the javascript code
window.onload = function () {
document.getElementById("input").addEventListener('change', myFunction);
function myFunction() {
document.getElementById("myButton").disabled = true;
let options = document.getElementById("colours").options;
let selectionMade = false;
let selectedValue = "";
for (let i = 0; i < options.length; i++) {
if(document.getElementById("input").value == options[i].value) {
selectedValue = document.getElementById("input").value;
selectionMade = true;
document.getElementById("result").innerHTML = "Selected : " + selectedValue + ".";
document.getElementById("myButton").disabled = false;
}
}
if (selectionMade === false) {
document.getElementById("result").innerHTML = "Please only select one of the available choices";
}
}
}
Here is a link to a working jsBin.
Updated: to answer question 2 of getting the data-id attribute of the option selected.
To get the data-id attribute of the option selected, in your javascript you can get using this way:
let selectedDataId = options[i].getAttribute('data-id');
After you get this value, you can update a hidden input form inside your form so that the value is submitted along.
Here is a link to an updated jsBin