Skip to content

Magento 2 validation problem (validate just the first field)

Simplify tthe code especially.
Probem: only the first elemts will be validated on submit
field-2 will be validated if I’ll remove first field. Strange problem. Not depends of M2 vesion. That’s phtml inclided to the CMS page

<form action="#" method="post" id="testform_01" class="testform">

    <div class="form-row">
        <label for="field-1">Text</label>
        <input type="text" id="field-1" data-validate='{"required":true}'/>
    </div>

    <div class="form-row">
        <label for="field-2">Text</label>
        <input type="text" id="field-2" data-validate='{"required":true}'/>
    </div>

    <div class="buttons">
        <button class="form-submit">Submit</button>
    </div>

</form>

<script type="text/x-magento-init">
    {
        "#testform_01": {
            "validation": {}
        }
    }
</script>