How to create multiple password checks validation with Yup and RHF? - yup

How to create multiple password checks validation with Yup and RHF?
I have register yup schema and i wanna to add multiple password checks validation like in the nike.com
export const RegisterSchema = yup.object().shape({
email: yup.string().email('Please enter a valid email address.').required('Email is a required field.'),
password: yup
.string()
.required('required')
.min(8, 'Minimum of 8 characters')
.matches(RegExp('(.*[a-z].*)'), '1 lowercase letter')
.matches(RegExp('(.*[A-Z].*)'), '1 uppercase letter')
.matches(RegExp('(.*\\d.*)'), '1 number'),
firstName: yup
.string()
.matches(/^([^0-9]*)$/, 'First name should not contains numbers.')
.max(40, 'First name cannot exceed 40 characters.')
.required('Please enter a first name.'),
lastName: yup
.string()
.matches(/^([^0-9]*)$/, 'Last name should not contains numbers.')
.max(40, 'Last name cannot exceed 40 characters.')
.required('Please enter a last name.'),
dateOfBirth: yup.string().required('Please enter a date of birth.'),
country: yup.string().required('Please enter a country.'),
gender: yup.string().required('Please select a preference.'),
})

You've to use the criteriaMode: 'all' option with useForm.
https://react-hook-form.com/api/useform/[![criteriaMode option]1]1
Here is a working example (v7):
👉🏻 https://codesandbox.io/s/react-hook-form-v6-errors-validatecriteriamode-all-p9xm6

Related

Referencing Column in Different Schema for One-to-One Relationship in OpenAPI 3.1

I'm working with two schemas User and Post. User has fields username, bio, email, and password and Post has fields username, text, and timestamp.
I want to associate field username in Post with field username in User. They will be in a one-to-one relationship.
I have come up with the below specification:
components:
schemas:
Post:
type: object
required:
- username
- text
discriminator:
propertyName: username
mapping:
username: '#/components/schemas/User'
properties:
username:
description: Username of the person who posted
type: string
text:
description: Contents of the post
type: string
timestamp:
description: ISO-8601 timestamp of when the post was made
type: string
format: date-time
User:
type: object
required:
- username
- bio
- email
- password
properties:
username:
description: Username for user
type: string
$ref: '#/components/schemas/Post'
bio:
description: Profile headline
type: string
email:
description: User's email address for notifications and security updates
type: string
password:
description: User's password for login
type: string
Is this correct ?

How can I access Country Name in ISO formate from ReactivePhoneFormField<PhoneNumber> widget?

How can I access Country Name or Nationality from the following after a country iso is selected by the user:
ReactivePhoneFormField<PhoneNumber>(
defaultCountry: IsoCode.GB,
decoration: InputDecoration(
labelText: 'Contact number', border: OutlineInputBorder()),
formControlName: 'phoneNumber',
// selectionHeightStyle: BoxHeightStyle.max,
// showFlagInInput: true,
//TODO? Phone verification. After signup?
/* validationMessages: (control) => {
ValidationMessage.required:
'Please provide your contact phone number',
'phoneNumber': 'Please enter a valid contact number'
},*/
countrySelectorNavigator:
CountrySelectorNavigator.modalBottomSheet(
favorites: [IsoCode.GB, IsoCode.ZA, IsoCode.US]),
),
As well , do tell that which of the following (onSaved,onSubmitted,onTap,onEditingComplete) functions available in this widget provide the samefunctionality as of onChanged function of textfield!

In Firestore, how to ignore unwanted inputs for creation?

As we all know we can create a record like this:
const docRef = db.collection('forms').add({
name: 'Some name',
address: 'Some address'
userId: 'some user ID'
});
However, if some users (authenticated users) POST to your store:
const docRef = db.collection('forms').add({
name: 'Some name',
address: 'Some address'
userId: 'some user ID',
unwantedData1: 'xxx,
unwantedData2: 'xxx,
unwantedData3: 'xxx,
unwantedData4: 'xxx,
unwantedData5: 'xxx,
unwantedData6: 'xxx,
unwantedData6: 'xxx,
... // <- too many rubbish params
});
Although we have the security rule, however, some attackers can register a dummy account and do something like that. How to prevent this in Firestore?
Many thanks.
You can do this with Firestore Security Rules using hasOnly.
You would do something like this:
allow write: if resource.data.keys().hasOnly([ <your whitelisted properties> ])
If for some reason you can't use the rules in this way, or you need to do more advanced checks, you could create a Cloud Function with a Firestore Trigger that validates the document and deletes it if something is wrong.

Translate custom validationErrorMessages in typo3 forms with locallang.xlf

I use locallang.xlf to translate my form (typo3 9.5.5, formextension).
my customform.yaml:
renderables:
-
properties:
fluidAdditionalAttributes:
required: required
validationErrorMessages:
-
code: 1221560910
message: 'My Custom Message'
code: 1221560718
message: 'My Custom Message'
-
code: 1347992400
message: 'My Custom Message'
-
code: 1347992400
message: 'My Custom Message'
options:
products: 'Products'
miscellaneous: 'Sonstiges'
prependOptionLabel: 'Please Specify'
type: SingleSelect
identifier: subject
label: 'Your Subject:'
validators:
-
identifier: NotEmpty
-
my locallang.xlf:
<trans-unit id="element.subject.properties.prependOptionLabel">
<source>Please Specify --Works!</source>
</trans-unit>
<trans-unit id="element.subject.properties.options.products">
    <source>Products --Works!</source>
</trans-unit>
<trans-unit id="element.subject.properties.validationErrorMessages.message">
<source>Custom Message -Doesn't work!</source>
</trans-unit>
With an exact translation key it works, except validationErrorMessages.
Does anyone know how to translate these?
You can use the following translation keys for validation error codes. 1221559976 is the code for the EmailAddress validator:
<trans-unit id="validation.error.1221559976">
<source>Please enter valid email address. Thanks!</source>
<target>Bitte gebe eine gültige E-Mail-Adresse ein. Danke!</target>
</trans-unit>
<trans-unit id="MyContactForm.validation.error.1221559976">
<source>Please enter valid email address. Thank you very much!</source>
<target>Bitte gebe eine gültige E-Mail-Adresse ein. Vielen herzlichen Dank!</target>
</trans-unit>
The latter will override the first, as it contains the form identifier and is therefore more specific.
Keep in mind that both of these translation keys will not work if you already set a custom message in your form definition!
This means, the last three lines of the following example have to be removed:
renderables:
-
defaultValue: ''
identifier: email
label: Email
type: Text
properties:
fluidAdditionalAttributes:
placeholder: 'Email address'
### Don't set this if you want to translate the message:
#validationErrorMessages:
# - code: 1221559976
# message: 'Please enter a valid email address, dear.'

How to set up Swagger with express?

I am using the {swagger-express} library and my code is all in CoffeeScript. For my definition, I have:
app.use swagger.init app,
apis: ['./src/routes.coffee', './src/models.yml']
apiVersion: '0.1.0'
basePath: "http://localhost:#{port}"
info:
title: 'My API'
description: 'A complete listing of all API functions'
swaggerUI: path.join __dirname, 'public'
swaggerURL: '/swagger'
require('./src/routes') app
In routes, I have:
###
* #swagger
* path: /login
* operations:
* - httpMethod: POST
* summary: Login with username and password
* notes: Returns a user based on username
* responseClass: User
* nickname: login
* consumes:
* - text/html
* parameters:
* - name: username
* description: Your username
* paramType: query
* required: true
* dataType: string
* - name: password
* description: Your password
* paramType: query
* required: true
* dataType: string
###
and that works fine. My model.yml file is:
definitions:
User:
properties:
user_id:
type: string
description: Unique ID to represent the user
first_name:
type: string
description: First name of the Uber user.
last_name:
type: string
description: Last name of the Uber user.
email:
type: string
description: Email address of the Uber user
picture:
type: string
description: Image URL of the Uber user.
promo_code:
type: string
description: Promo code of the Uber user.
But that doesn't show up in the api-docs.json. I am trying to define the models in one file and the paths in another. Can that be done?
I don't think it will work because each format is read separately and saved in a hash which is uses the resourcePath as the key.
https://github.com/fliptoo/swagger-express/blob/a5560af936e5398affe36d347af5be2a1bb64fc2/lib/swagger-express/index.js#L27
Any further declaration of the same resourcePath will override the previous declaration.
I tested with an updated yml format with a resourcePath, the name models instead of definitions and a unique id for the model. This made the models show up but none of my other information :/
resourcePath: /login
models:
User:
id: User
properties:
user_id:
type: String
description: Unique ID to represent the user
first_name:
type: String
description: First name of the Uber user.
last_name:
type: String
description: Last name of the Uber user.
email:
type: String
description: Email address of the Uber user
picture:
type: String
description: Image URL of the Uber user.
promo_code:
type: String
description: Promo code of the Uber user.
The example on their github makes it look like this will work but I couldn't make it work.