Possible to add an optional validation based on if another optional value is true?


#1

If an optional value is true, I want to add another optional value to the schema. The following doesn’t work as intended. If I pass

{ setting_is_allowed: true, setting: 200 }

setting is not returned in the output. I was trying to build a rule, but I couldn’t find enough examples to piece together the exact scenario I am dealing with.

optional(:setting_is_allowed).maybe.when(:true?) do
  optional(:setting).maybe {none? | int?}
end

#2

So, you need to check if setting key is present or not?