Validated inputs are not initially marked as invalid until the value changes. How to restore this initial state?
My problem is in the details: I have a simple order form. If the user clicks the "add item" button, I clone the first item and an empty input field. But since I use html5 validation, emptying makes them invalid.
This happens after clicking the "Add Product" button, even if the first set of fields is valid:

Demo: http://jsfiddle.net/WEHdp/ (view in Firefox):
<form action="/orders/preview" method="post">
<div class="orderData">
<input name="order[order_items_attributes][0][articleno]" pattern="[0-9]{4}" required /> /
<input name="order[order_items_attributes][0][colorno]" pattern="[0-9]{3}" required />
<div>
<a href="#" class="removeOrder">Remove product</a>
<a href="#" class="addOrder">Add product</a>
</div>
</div>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js"></script>
<script>
$(document).ready(function() {
$(".addOrder").live("click", function (event) {
event.preventDefault();
$('.orderData:first').clone().insertAfter(".orderData:last");
$('.orderData:last input').val("");
});
$(".removeOrder").live("click", function (event) {
event.preventDefault();
if($('.orderData').size() > 1){
$(this).parents('.orderData').remove();
}
});
});
</script>
iGEL source
share