conditional optional
See original GitHub issueIs there any way to have a ‘conditional optional’? I’m trying to make a situation work where a key would only be required when another key is set.
new SimpleSchema({
firstname: {
type: String,
label: "First name",
optional: true
},
lastname: {
type: String,
label: "Last name",
optional: true
}
})
Considering this schema. How would I go ahead and make lastname required or optional: false
when and only when firstname is set?
Issue Analytics
- State:
- Created 10 years ago
- Comments:16
Top Results From Across the Web
What's the difference between Required, Conditional and ...
OPTIONAL – This indicates that the MSDS system cannot determine when or for which students the data are required. This does not mean...
Read more >What is the difference between Required, Conditionally ...
Optional fields are not required to save the credit as complete and have no impact on scoring. They are included to give participants...
Read more >Conditional optional checks - Using Swift
I have two optional properties and would like to know how to elegantly unwrap them to perform a conditional check.
Read more >Mandatory/Conditional/Optional Fields - SmartBear Community
HI, I need help to create json schema with mandatory/conditional/optional field. For mandatory i am taking it inside "required".
Read more >Conditionally optional/conditionally readonly properties #44261
the intent here is that getKey is optional if T is string or a subtype of string , but otherwise getKey is mandatory....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi Aldeed,
With the recent deprecation of valueIsAllowed I instead tried to use a
custom
method to do this conditional optional check. But this issue (#30) seems to have resurfaced.Consider this schema:
In this example the
custom
method isn’t triggered when thefirstname
is empty.Do you know how we could solve this?
Thanks.
No, sorry, what I said was not correct. They are not SimpleSchema instances, they are Collection2 instances. ( do you have a reference to where you do those basic tests ? I am not familiar with the code yet, but interested and also interested in having an implementation of foreign Keys. )
And the problem here was, that I didn’t check if the key was set, so I tried to validate something which was not updated. Now I check in my custom function if the key isSet and if so, I check for the value existing in the other collection. Works like a charm now 😃
Thanks for the help !