Is there a way to validate form fields, that should remain "optional" (not required)?
Even if I set "required" to false in both cases (required or not), Magento nags at the optional field, when it is left empty (and there is a red "*", which marks a required field):
<?= $block->isRequired() ?
' data-validate=\'{"required":false, "validate-custom-whatever":true}\'' :
' data-validate=\'{"required":false, "validate-custom-whatever":true}\''
?>
So, it seems to me, that there is no way to validate optional fields, without adding an extra case to the validator, like so (pseudocode):
if(value == '')
{
return true
}
else
{
// do validation and return true or false - depending on the validation result
}
Is this really the correct way, of doing it? Or is there a more beautiful "Magento way" of doing this?