joi
joi copied to clipboard
Cannot get the flag/presence of a property
Support plan
- is this issue currently blocking your project? (yes/no): yes
- is this issue affecting a production system? (yes/no): no
Context
- node version: v16.14.0
- module version with issue: v17.9.2
- last module version without issue: N/A
- environment (e.g. node, browser, native): browser
- used with (e.g. hapi application, another framework, standalone, ...): react-hook-form resolver for joi
- any other relevant information: N/A
What are you trying to achieve or the steps to reproduce?
I'm trying to get the presence of a field. So, trying to learn if presence is optional or required. In order to get that I'm using $_getFlag
but it doesn't work.
What was the result you got?
Works:
console.log('1. firstName', sampleFormSchema.extract('firstName')._flags.presence);
Works:
console.log('2. firstName', sampleFormSchema.$_terms.keys.find((key) => key.key === 'firstName')?.schema._flags.presence);
Doesn't Work:
console.log('3. firstName', sampleFormSchema.$_getFlag('firstName'));
console.log('3. firstName', sampleFormSchema.$_getFlag('firstName', 'presence'));
What result did you expect?
Expected to receive 'option' or 'required' but received undefined.