Validation issue with conditional fields rendering #81
-
Hi Ivan, If a Country is selected and has NO state options, an InputField is rendered. When an InputField is rendered it is not required but the validation for the select is still required. Here is an example of this here: CodeSandbox Select a Country that does not have regions and an Input will render. trying to submit will trigger invalid for that field but it should not be required. Is there a way to invalidate the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @lscmaro, <SelectField
name="customer_info.region"
options={regionOptions}
type="regions"
label="State"
validations={[
{
rule: (value) => regionOptions ? !!value : true, // Return false only if there are some regionOptions and no value
message: "State is Required",
deps: [regionOptions] // This is important for updating the validation when the regionOptions change
}
]}
/> |
Beta Was this translation helpful? Give feedback.
-
@lscmaro <SelectField
name="customer_info.region"
options={regionOptions}
type="regions"
label="State"
required={regionOptions ? "State is Required" : false}
/> (don't forget to update the |
Beta Was this translation helpful? Give feedback.
@lscmaro
I just released a version 1.1.1 of
@formiz/core
so you can write the following code:(don't forget to update the
@formiz/core
package to get the fix 😊)