Closed m-vo closed 5 years ago
The browser validation can be disabled in the Contao form configuration.
Sure, but only for the whole form and not for a single field.
Of course it's possible to add a custom template or custom js that works around this, but I think it's a valid use case that should work out of the box, wdyt?
Correct, that's default HTML5 behavior.
But I can render fields that initially aren't valid - a required but empty textfield for instance - and the browser won't complain until I'm hitting submit.
Just noticed: This problem does not exist when using chrome.
It does not work to remove the required
attribute before the select was updated and to add the required
attribute after the select options were updated. The select will show as failing nonetheless.
The key is to reset the form, so that the input state (whether the select was touched) will be truncated.
Doesn't that reset all input in the form? Thats at least how a type="reset"
input button works…?
That's true but it only happens on page load and, in addition, the current values are kept as of 1d60273b66f6319aeb77314eff06af9f593a2895.
However, I am uncertain, whether we can experience data loss nonetheless. Then, we have to decide, whether there is a practical solution to this issue.
To tackle this issue, there is no gold solution available, however, one could remove the required
attribute on the dependent select via JS.
@aschempp and I agreed upon the fact, that it would have further drawbacks when removing the required
attribute. We, therefore, are not able to fix this issue.
With required fields + active HTML5 browser validation, empty fields (nothing selected in the primary dropdown) will get marked as failing on page load.
I'm not sure if the browser validation can be reset (found nothing obvious on that), so the required attribute should probably be removed in this case or made sure the form does not get altered when initially rendering.